Select lengthプロパティ

Select 对象参考手册Select オブジェクト

定義と用法

length プロパティは、ドロップダウンリスト内のオプションの数を返します。

構文

selectObject.length=number


ブラウザサポート

Internet ExplorerFirefoxOperaGoogle ChromeSafari

すべての主要ブラウザが length プロパティをサポートしています


例

例

ドロップダウンリストのオプション数を表示:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>サンプル(example.com)</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()">ドロップダウンリストにはいくつのオプションがありますか?</button>

</body>
</html>

試してみる »


Select 对象参考手册Select オブジェクト その他の拡張