Document Object Model (DOM)とは、W3Cから勧告されているHTML文書やXML文書をアプリケーションから利用するためのAPIである。
Elementオブジェクトのプロパティ、メソッド及びイベントもサポートする。
JavaScriptのOptionオブジェクトには次のプロパティがある。
プロパティ | 説明 |
---|---|
defaultSelected | デフォルトで選択されているかどうか |
disabled | 要素が無効かどうか |
form | フォーム要素の参照 |
index | インデックス(0~) |
selected | 選択されているかどうか |
text | 選択肢のテキスト |
value | 選択肢の値 |
<form>
<select>
<option id="option1" value="savings">普通預金</option>
<option id="option2" value="checking">当座預金</option>
</select>
</form>
<table>
<thead>
<tr>
<th>index<th>
<th>text<th>
<th>value<th>
</tr>
</thead>
<tbody>
<tr>
<td id="index1"><td>
<td id="text1"><td>
<td id="value1"><td>
</tr>
<tr>
<td id="index2"><td>
<td id="text2"><td>
<td id="value2"><td>
</tr>
</tbody>
</table>
<script>
let option1 = document.getElementById("option1");
document.getElementById("index1").innerHTML = option1.index;
document.getElementById("text1").innerHTML = option1.text;
document.getElementById("value1").innerHTML = option1.value;
let option2 = document.getElementById("option2");
document.getElementById("index2").innerHTML = option2.index;
document.getElementById("text2").innerHTML = option2.text;
document.getElementById("value2").innerHTML = option2.value;
</script>
index | text | value |
---|---|---|