如何获得select被选中option的值
2017-11-16 13:34
316 查看
一:JavaScript原生的方法
1:拿到select对象: var myselect=document.getElementById(“test”);
2:拿到选中项的索引:var index=myselect.selectedIndex ; // selectedIndex代表的是你所选中项的index
3:拿到选中项options的value: myselect.options[index].value;
4:拿到选中项options的text: myselect.options[index].text;
二:jQuery方法(前提是已经加载了jquery库)
1:var options=$(“#test option:selected”); //获取选中的项
2:alert(options.val()); //拿到选中项的值
3:alert(options.text()); //拿到选中项的文本
有写错的地方,欢迎指正,不胜感激!
笔者QQ群:148042812
1:拿到select对象: var myselect=document.getElementById(“test”);
2:拿到选中项的索引:var index=myselect.selectedIndex ; // selectedIndex代表的是你所选中项的index
3:拿到选中项options的value: myselect.options[index].value;
4:拿到选中项options的text: myselect.options[index].text;
二:jQuery方法(前提是已经加载了jquery库)
1:var options=$(“#test option:selected”); //获取选中的项
2:alert(options.val()); //拿到选中项的值
3:alert(options.text()); //拿到选中项的文本
有写错的地方,欢迎指正,不胜感激!
笔者QQ群:148042812
相关文章推荐
- 如何获得select被选中option的value和text
- 如何获得select被选中option的value和text
- jquery 获取下拉框 某个text='xxx'的option的属性 非选中 如何获得select被选中option的value和text和......
- 如何获得select被选中option的value和text和其他属性值
- 如何获得select被选中option的value和text和......
- 如何获得select标签下option的值
- 如何获得select选中的是那个option
- jquery去重复 如何去除select控件重复的option
- jquery 如何去除select 控件重复的option
- 解决如何通过循环来使用数据库的值设置jsp的select标签的option值
- JavaScript为select添加option,select选项变化时的处理,获取slelect被选中的值
- 关于如何删除掉select中的option元素,兼容IE、Firefox
- Jquery获得select下拉选项option的值:
- sencha-touch1.1-combobox(selectfield)如何获得选中的value
- select如何获取被选中的opinion
- select标签如何传递选中option的value值与text值
- 如何通过js动态设置select中option选中
- 如何修改jquery easyui select中option背景颜色
- 如何根据select选择的值反查option的属性
- 如何设置select-option的多项起始默认值