获得下拉列表中的选中值

来源:互联网 发布:京津冀生态环境数据 编辑:程序博客网 时间:2024/05/21 22:58
<!doctype html>
<html>
<head>
<!--获得下拉列表中的选中值-->
<style>
</style>
<script>
function test(){
var tes=document.getElementById("tes");//获取select元素
alert(tes.options["内容值:"+tes.selectedIndex].innerHTML+"元素值"+tes.options[tes.selectedIndex].value);//通过selectedIndex获得选中的选项的下标,再通过options[]集合获取选中的option元素
}
</script>
<meta charset="UTF-8">
</head>
<body>
<select id="tes" onchange="test()"><!--选项值改变时触发onchange()事件-->
<option value="帅哥" checked="checked" id="test1">帅哥</option>
<option value="美女" id="test2">美女</option>
<option value="ladybody" id="test3">ladybody</option>
</select>
</body>
</html>
原创粉丝点击