<script type="text/javascript">
function onc(){
var sele = document.getElementById("selectid");
//selectdIndex 返回当前选中option的索引
var index = sele.selectedIndex;
//otions返回当前id中的option集合,索引从1开始
sele.options[index].setAttribute("checked","checked");//为当前索引设置一个默认值属性
alert(index);//使用警告提示打印当前所在的索引值
alert(sele.options[index].value);//使用警告提示打印当前value值;
alert(sele.options[index].innerHTML);//使用警告提示打印打印当前文本值;
}
</script>
</head>
<body>
<form action="new_file.html" method="post">
<select id="selectid" onchange="onc()">
<option value="">1</option>
<option value="">2</option>
<option value="">3</option>
</select>
<input type="submit" value="提交"/>
</form>
</body>
javaScript获取select下拉列表的属性值
最新推荐文章于 2022-06-04 10:01:20 发布