简单教程
提交运行
代码编辑器:
<script> function displayResult(){ var x=document.getElementById("mySelect").selectedIndex; alert(document.getElementsByTagName("option")[x].value); } </script> <form> 选择你最喜欢的水果: <select id="mySelect"> <option value="apple">Apple</option> <option value="orange">Orange</option> <option value="pineapple">Pineapple</option> <option value="banana">Banana</option> </select> </form> <button type="button" onclick="displayResult()">选择的水果的值</button>
运行结果: