サイズプロパティを選択
例
ドロップダウンリストに表示されるオプションの数を変更します。
document.getElementById("mySelect").size = "4";
定義と使用法
sizeプロパティは、ドロップダウンリストのsize属性の値を設定または返します。
size属性は、ドロップダウンリストに表示されるオプションの数を指定します。
注: ChromeとSafariでは、size = "2"とsize = "3"でsize属性が期待どおりに機能しない場合があります。
ブラウザのサポート
Property | |||||
---|---|---|---|---|---|
size | Yes | Yes | Yes | Yes | Yes |
構文
sizeプロパティを返します。
selectObject.size
サイズプロパティを設定します。
selectObject.size = number
プロパティ値
Value | Description |
---|---|
number | Specifies the number of visible options in a drop-down list. If the value is greater than 1, but lower than the total number of options in the list, the browser will add a scroll bar to indicate that there are more options to view. |
技術的な詳細
戻り値: | ドロップダウンリストに表示されるオプションの数を表す数値 |
---|
その他の例
例
ドロップダウンリストに表示されているオプションの数を返します。
var x = document.getElementById("mySelect").size;
関連ページ
HTML参照:HTML <select>サイズ属性
❮オブジェクトを選択