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>');
$("#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>');
相关文章推荐
- jQuery ZeroClipboard中Flash定位不准确的解决方案
- JQuery UI datepicker在选择startDate与endDate时手动清空数据后,时间选择依然有限制问题!
- jquery 模糊匹配问题记录
- jquery实现Ctrl+Enter提交表单的方法
- 带在线客服返回顶部的jquery右下角弹出菜单-代码
- jquery中filter的使用
- jQuery Ajax学习与运用
- JQuery中$.ajax()方法参数详解
- jQuery $符号冲突
- js和jquery页面初始化加载函数的方法及先后顺序
- jQuery对select操作小结(遍历option,操作option)
- jQueryEasyUI Messager基本使用
- Jquery trigger 与 triggerHandler
- jquery模拟select
- 表单验证插件jquery.validate的使用方法演示
- 屏蔽系统自带的yii\web\JqueryAsset
- JQuery对象选择详细说明
- jQuery实现html元素拖拽
- jQuery部分源码帮助理解
- jquery 2.0.3代码结构