javascript获取select的当前值示例代码(兼容IE/Firefox/Opera/Chrome)
JavaScript获取Select当前值写法:
var value = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].value;
var text = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].text;
例子:
<script>
function check() {
var select = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].value;
alert(select);
}
</script>
<select name="select" id="select">
<option value="test1" selected="selected">Test1</option>
<option value="test2">Test2</option>
</select>
<input type="button" value="我要试试" onclick="check()"/>
栏 目:JavaScript代码
下一篇:详解javascript遍历方式
本文标题:javascript获取select的当前值示例代码(兼容IE/Firefox/Opera/Chrome)
本文地址:http://www.codeinn.net/misctech/30328.html