HTMLSelectElement: options 属性
HTMLSelectElement.options 只读属性返回一个 HTMLOptionsCollection,其中包含 <select> 元素内的所有 <option> 元素。
值
一个包含 <select> 元素内的 <option> 元素的 HTMLOptionsCollection。
示例
HTML
html
<label for="test">Label</label>
<select id="test">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
JavaScript
js
const select = document.getElementById("test");
for (const option of select.options) {
console.log(option.label); // "Option 1" and "Option 2"
}
规范
| 规范 |
|---|
| HTML # dom-select-options-dev |
浏览器兼容性
加载中…