- 时间:2020-09-27 09:12 编辑: 来源: 阅读:
- 扫一扫,手机访问
摘要:javascript获取select的当前值示例代码(兼容IE/Firefox/Opera/Chrome)
[b]
JavaScript获取Select当前值写法:
[/b]var value = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].value;
var text = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].text;
[b]例子:
[/b]
<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()"/>