JSP页面获取下来框select选中项的值和文本的方法

<select id="username"  name="">

     <option   value="1">jyy</option>  

     <option   value="2">abc</option>

</select>

code:

一:javascript方法

var  mySelect=document.getElementById("username");

var index=myselect.selectedIndex ;  

选中项的value:  myselect.options[index].value;

选中项的text:  myselect.options[index].text;

二:jquery方法(前提是已经加载了jquery库)

var options=$("#test option:selected"); 

选中项的value:alert(options.val());  

选中项的text:alert(options.text());  

posted @ 2014-03-08 16:31  姜莹莹  阅读(4919)  评论(0编辑  收藏  举报