如何获得select被选中option的value和text
2016-05-04 09:32
567 查看
一: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()); //拿到选中项的文本
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()); //拿到选中项的文本
相关文章推荐
- require()函数
- UIImage的两种初始化方式
- include()和require()是特殊的语言结构,在条件语句中使用必须将其放在语句组中
- UI高总结
- activiti uuid主键
- activiti uuid主键
- Extension Methods (C# Programming Guide)
- count2array_count_values .php
- CodeForces 666A. Reberland Linguistics【DP】
- 让UILabel的文字顶部对齐
- String、Stringbuilder、Stringbuffer区别及应用场景
- Leetcode_347_Top K Frequent Elements
- 【Baltic2014】【BZOJ3917】Sequence
- C#中StringBuilder类的使用总结
- 95. Unique Binary Search Trees II
- 96. Unique Binary Search Trees
- day4.08总结_UI控件
- mysql5.5提示Deprecated: mysql_query(): The mysql extension is deprecated
- UITableView 零散知识点总结
- Java基础学习之--Break/Continue/Return