要获得下拉列表中的选项计数,请使用JavaScript中的length属性。
您可以尝试运行以下代码以在下拉列表中找到选项数量-
<!DOCTYPE html>
<html>
<body>
<form id="myForm">
<select id="mySelect">
<option>One</option>
<option>Two</option>
<option>Three</option>
</select>
</form>
<script>
var val = document.getElementById("mySelect").length;
document.write("<br>Options in the DropDown list: "+val);
</script>
</body>
</html>