<select id="tryselect" name="">
<option value="1">text 1</option>
<option value="2">text 2</option>
</select>
<script language="JavaScript">
<!--
var myid = document.getElementById("tryselect");
alert(myid.options[myid.selectedIndex].value +"\n" +myid.options[myid.selectedIndex].text)
//-->
</script>
js获取select的值
最新推荐文章于 2022-10-19 04:21:39 发布
本文介绍了一种使用JavaScript获取HTML中下拉选择框(select元素)的选定选项值及文本的方法。通过getElementById方法定位到指定ID的select元素,并利用options和selectedIndex属性获取当前选中的值和文本。
846

被折叠的 条评论
为什么被折叠?



