HTMLDOMオプションオブジェクト
オプションオブジェクト
Optionオブジェクトは、HTMLの<option>要素を表します。
オプションオブジェクトにアクセスする
getElementById()を使用して、<option>要素にアクセスできます。
例
var x = document.getElementById("myOption");
ヒント: フォームの要素コレクションまたはドロップダウンリストのオプションコレクションを検索して、Optionオブジェクトにアクセスすることもできます。
オプションオブジェクトを作成する
document.createElement()メソッドを使用して、<option>要素を作成できます。
例
var x = document.createElement("OPTION");
オプションオブジェクトのプロパティ
Property | Description |
---|---|
defaultSelected | Returns the default value of the selected attribute |
disabled | Sets or returns whether an option is disabled, or not |
form | Returns a reference to the form that contains the option |
index | Sets or returns the index position of an option in a drop-down list |
label | Sets or returns the value of the label attribute of an option in a drop-down list |
selected | Sets or returns the selected state of an option |
text | Sets or returns the text of an option |
value | Sets or returns the value of an option to be sent to the server |
標準のプロパティとイベント
Optionオブジェクトは、標準のプロパティとイベントもサポートします。
関連ページ
HTMLリファレンス:HTML <option>タグ