jQuery中对select下拉框的基本操作

来源:互联网 发布:江苏微盛网络 怎么样 编辑:程序博客网 时间:2024/06/05 00:44
1.为select添加事件,当选择其中一项时触发
$("#select_id").change(function(){ });
也可以用jQuery UI插件中的selectmenu方法来实现下拉刷新,不需要绑定事件,如$('#reg_class').selectmenu(‘refresh’);

2.获取Select选择的Value
var checkValue=$("#select_id").val();

3.获取select选择的Text
var checkText=$("#select_id").find("option:selected").text();

4.获取select选择的索引值
var checkIndex=$("#select_id ").get(0).selectedIndex; 

5.获取select最大的索引值
var maxIndex=$("#select_id option:last").attr("index");  

6.设置Select索引值为1的项选中
$("#select_id ").get(0).selectedIndex=1;

7.设置Select的Value值为4的项选中
$("#select_id ").val(4);

8.设置Select的Text值为jQuery的项选中
$("#select_id option[text='jQuery']").attr("selected", true);

9.追加option选中项
$("#select_id ").append('<option selected="selected" value="">请选择</option>');

0 0
原创粉丝点击