如何获得select被选中option的value和text和其他属性值
来源:互联网 发布:mac关闭icloud drive 编辑:程序博客网 时间:2024/05/16 17:22
我想获取select选中的value,或者text,或者……
比如这个:
<select id="select"> <option value="A" url="http://www.baidu.com">第一个option</option> <option value="B" url="http://www.qq.com">第二个option</option></select>
一:JavaScript原生的方法
1:拿到select对象: var myselect=document.getElementById("select");2:拿到选中项的索引:var index=myselect.selectedIndex ; // selectedIndex代表的是你所选中项的index3:拿到选中项options的value: myselect.options[index].value;4:拿到选中项options的text: myselect.options[index].text;5:拿到选中项的其他值,比如这里的url: myselect.options[index].getAttribute('url');
二:jQuery方法
1:var options=$("#select option:selected"); //获取选中的项2:alert(options.val()); //拿到选中项的值3:alert(options.text()); //拿到选中项的文本4:alert(options.attr('url')); //拿到选中项的url值
阅读全文
0 0
- 如何获得select被选中option的value和text和其他属性值
- 如何获得select被选中option的value和text
- 如何获得select被选中option的value和text
- 如何获得select被选中option的value和text和......
- jquery获得select选中项的text和value
- web 获取select中被选中option的value和text
- js实例,获取选中select标签的value和option text值
- jQuery获取Select选中的Text和Value,根据Value值动态添加属性等
- jQuery获取Select选中的Text和Value,根据Value值动态添加属性等
- jQuery获取Select选中的Text和Value,根据Value值动态添加属性等
- jQuery获取Select选中的Text和Value,根据Value值动态添加属性等
- jQuery获取Select选中的Text和Value,根据Value值动态添加属性等
- 如何获得select被选中option的值
- 下拉列表select动态添加option和获取选中的option的值和value
- jQuery操作Select获取被选中的Text和Value
- 用脚本语言如何得到在select中被选中的选项的value和text
- select标签下option标签里value属性有什么用以及和text的区别
- jQuery获取Select option 选择的Text和Value
- 错题
- 菜单导航栏总结
- vue踩坑系列——slot
- JS(history,location的使用)返回上一页以及返回上一页并刷新
- 基于Token的身份验证——JWT
- 如何获得select被选中option的value和text和其他属性值
- 精通算法系列-复制图形
- Android中WiFi的使用------WiFimanager
- 共基、共射、共集基本放大电路
- HTML中a标签中href=""的几种用法
- Mysql随机访问记录
- 查Postgresql 数据库、各表占用磁盘大小
- [HTML/CSS]盒子模型,块级元素和行内元素
- Java学习笔记