Select length 屬性
Select 對(duì)象定義和用法
length 屬性可返回下拉列表中選項(xiàng)的數(shù)目。
語(yǔ)法
selectObject.length=number
瀏覽器支持
所有主要瀏覽器都支持 length 屬性
實(shí)例
實(shí)例
顯示下拉列表的選項(xiàng)數(shù)目:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>W3Cschool在線教程(w3cschool.cn)</title>
<script>
function displayResult(){
alert(document.getElementById("mySelect").length);
}
</script>
</head>
<body>
<form>
<select id="mySelect">
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>
</form>
<button type="button" onclick="displayResult()">下拉列表中有多少選項(xiàng)?</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>W3Cschool在線教程(w3cschool.cn)</title>
<script>
function displayResult(){
alert(document.getElementById("mySelect").length);
}
</script>
</head>
<body>
<form>
<select id="mySelect">
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>
</form>
<button type="button" onclick="displayResult()">下拉列表中有多少選項(xiàng)?</button>
</body>
</html>
嘗試一下 ?
Select 對(duì)象
更多建議: