您的位置:首页 > Web前端 > JQuery

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

2015-07-21 11:33 369 查看
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>');
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: