获得select被选中option的value和text

一: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方法

1:var options=$(“#test option:selected”); //获取选中的项

2:alert(options.val()); //得到选中项的值

3:alert(options.text()); //得到选中项的文本

posted @ 2017-09-09 13:12  喵嘻嘻  阅读(350)  评论(0)    收藏  举报