jquery 对select中的option…
来源:互联网 发布:蓝桥杯单片机 编辑:程序博客网 时间:2024/06/05 03:42
原文地址:jquery 对select中的option操作(转的) 作者:爱无痕
Jquery的功能很强大,下面介绍Jquery操作表单Select元素的用法:
jQuery获取Select元素,并选择的Text和Value:
1.$("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发
2. varcheckText=$("#select_id").find("option:selected").text();//获取Select选择的Text
3. var checkValue=$("#select_id").val();//获取Select选择的Value
4. var checkIndex=$("#select_id").get(0).selectedIndex; //获取Select选择的索引值
5. var maxIndex=$("#select_idoption:last").attr("index");//获取Select最大的索引值
jQuery获取Select元素,并设置的 Text和Value:
实例分析:
1. $("#select_id ").get(0).selectedIndex=1;//设置Select索引值为1的项选中
2. $("#select_id ").val(4); //设置Select的Value值为4的项选中
3. $("#select_id option[text='jQuery']").attr("selected",true); //设置Select的Text值为jQuery的项选中
jQuery添加/删除Select元素的Option项:
实例分析:
1. $("#select_id").append("<optionvalue='Value'>Text</option>");//为Select追加一个Option(下拉项)
2. $("#select_id").prepend("<optionvalue='0'>请选择</option>");//为Select插入一个Option(第一个位置)
3. $("#select_id option:last").remove();//删除Select中索引值最大Option(最后一个)
4. $("#select_id option[index='0']").remove();//删除Select中索引值为0的Option(第一个)
5. $("#select_id option[value='3']").remove();//删除Select中Value='3'的Option
6. $("#select_id option[text='4']").remove();//删除Select中Text='4'的Option
三级分类 <select name="thirdLevel" id="thirdLevel"
onchange="getFourthLevel()">
<option value="0"id="thirdOption">
请选择三级分类
</option>
</select>
</div>
四级分类:
<select name="fourthLevelId"id="fourthLevelId">
<option value="0"id="fourthOption">
请选择四级分类
</option>
</select>
</div>
.if($("#thirdLevel").val()!=0){
$("#thirdLevel option[value!=0]").remove();
}
if($("#fourthLevelId").val()!=0){
$("#fourthLevelId option[value!=0]").remove();
}//这个表示:假如我们希望当选择选择第三类时:如果第四类中有数据则删除,如果没有数据第四类的商品中的为默认值。在后面学习了AJAX技术后经常会使用到!
jQuery获取Select元素,并选择的Text和Value:
1.$("#select_id").change(function(){//code...});
2. varcheckText=$("#select_id").find("option:selected").text();
3. var checkValue=$("#select_id").val();
4. var checkIndex=$("#select_id").get(0).selectedIndex;
5. var maxIndex=$("#select_idoption:last").attr("index");
jQuery获取Select元素,并设置的 Text和Value:
实例分析:
1. $("#select_id ").get(0).selectedIndex=1;
2. $("#select_id ").val(4);
3. $("#select_id option[text='jQuery']").attr("selected",true);
jQuery添加/删除Select元素的Option项:
实例分析:
1. $("#select_id").append("<optionvalue='Value'>Text</option>");
2. $("#select_id").prepend("<optionvalue='0'>请选择</option>");
3. $("#select_id option:last").remove();
4. $("#select_id option[index='0']").remove();
5. $("#select_id option[value='3']").remove();
6. $("#select_id option[text='4']").remove();
三级分类 <select name="thirdLevel" id="thirdLevel"
onchange="getFourthLevel()">
<option value="0"id="thirdOption">
请选择三级分类
</option>
</select>
</div>
四级分类:
<select name="fourthLevelId"id="fourthLevelId">
<option value="0"id="fourthOption">
请选择四级分类
</option>
</select>
</div>
.if($("#thirdLevel").val()!=0){
$("#thirdLevel option[value!=0]").remove();
}
if($("#fourthLevelId").val()!=0){
$("#fourthLevelId option[value!=0]").remove();
}//这个表示:假如我们希望当选择选择第三类时:如果第四类中有数据则删除,如果没有数据第四类的商品中的为默认值。在后面学习了AJAX技术后经常会使用到!
- jquery 对select中的option…
- jquery 对select中的option操作
- jquery 对select中的option操作
- jquery 对select中的option操作
- 使用jQuery对select中的option进行排序
- jquery获得select option的值…
- jQuery获取Select option&nbs…
- 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 的操作
- @Resource注解
- struts技术的logic标签
- Hibernate的Criteria方法
- struts的token 防止form表单…
- struts2+displaytag翻页时In…
- jquery 对select中的option…
- Hibernate一对多(单向)
- ids for thisclass must be manually assigned before callingsave()
- spring - context:component-scan
- Struts2输入校验总结
- [自学问题总结]const 和 static readonly 区别
- DFS-hdu-2821-Pusher
- 商业智能给数据获取带来的局部效益案例
- Android编程习惯