<html>
<body>
<h1>演示如何访问 SELECT 元素</h1>
<select id="mySelect" size="4">
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>
<p>单击该按钮可获取在下拉列表中找到的 option 元素的数量。</p>
<button onclick="myFunction()">试一试</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("mySelect").length;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>