您的位置:首页 > Web前端 > JavaScript

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

2014-03-08 16:31 330 查看
<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());
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: