jquery select option事件
来源:互联网 发布:软件卸载 编辑:程序博客网 时间:2024/06/05 02:29
jQuery获取Select元素,并选择的Text和Value:
1. $("#id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发
2. var checkText=$("#id").find("option:selected").text(); //获取Select选择的Text
3. var checkValue=$("#id").val(); //获取Select选择的Value
4. var checkIndex=$("#id ").get(0).selectedIndex; //获取Select选择的索引值
5. var maxIndex=$("#id option:last").attr("index"); //获取Select最大的索引值
jQuery获取Select元素,并设置的 Text和Value:
实例分析:
1. $("#id ").get(0).selectedIndex=1; //设置Select索引值为1的项选中
2. $("#id ").val(4); // 设置Select的Value值为4的项选中
3. $("#id option[text='jQuery']").attr("selected", true); //设置Select的Text值为jQuery的项选中
jQuery添加/删除Select元素的Option项:
实例分析:
1. $("#id").append("<option value='Value'>Text</option>"); //为Select追加一个Option(下拉项)
2. $("#id").prepend("<option value='0'>请选择</option>"); //为Select插入一个Option(第一个位置)
3. $("#id option:last").remove(); //删除Select中索引值最大Option(最后一个)
4. $("#id option[index='0']").remove(); //删除Select中索引值为0的Option(第一个)
5. $("#id option[value='3']").remove(); //删除Select中Value='3'的Option
6. $("#id option[text='4']").remove(); //删除Select中Text='4'的Option
获取Select :
获取select 选中的 text :
$("#ddlRegType").find("option:selected").text();
获取select选中的 value:
$("#ddlRegType ").val();
获取select选中的索引:
$("#ddlRegType ").get(0).selectedIndex;
设置select:
设置select 选中的索引:
$("#ddlRegType ").get(0).selectedIndex=index;//index为索引值
设置select 选中的value:
$("#ddlRegType ").attr("value","Normal“);
$("#ddlRegType ").val("Normal");
$("#ddlRegType ").get(0).value = value;
设置select 选中的text:
var count=$("#ddlRegType option").length;
for(var i=0;i<count;i++)
{ if($("#ddlRegType ").get(0).options[i].text == text)
{
$("#ddlRegType ").get(0).options[i].selected = true;
break;
}
}
$("#id option[text='jQuery']").attr("selected", true);
设置select option项:
$("#id").append("<option value='Value'>Text</option>"); //添加一项option
$("#id").prepend("<option value='0'>请选择</option>"); //在前面插入一项option
$("#id option:last").remove(); //删除索引值最大的Option
$("#id option[index='0']").remove();//删除索引值为0的Option
$("#id option[value='3']").remove(); //删除值为3的Option
$("#id option[text='4']").remove(); //删除TEXT值为4的Option
清空 Select:
$("#ddlRegType ").empty();
- jquery select option事件
- jquery select option
- jquery select option 操作
- jQuery初始化select option
- JQuery Select 删除Option
- jquery select option
- jquery select option 操作
- jquery操作select option
- jquery select option
- jquery操作select option
- jquery select option选中
- JQuery select option用法
- select option jquery
- jquery select option操作
- select 的option选中事件
- jquery添加select的option
- jquery select option 动态选中
- JQuery操作select中的option
- OkHttp使用教程
- Java中的JIT机制对运行速度的优化
- JS获取当前时间戳的方法转换时间戳
- dlopen 相关错误
- js转换 underscore.js学习
- jquery select option事件
- C语言与ELF机器语言之间的关系
- B. Game of Robots
- 睿频/超频
- android中浮动菜单的基本实现
- 模拟 react 框架编码
- 适配器模式
- 关于android 横屏竖屏切换
- java 设计模式