HTMLSelectElement: remove() 方法
HTMLSelectElement.remove() 方法從該 select 元素的選項集合中移除指定索引處的元素。
語法
js
remove(index)
引數
index-
用於指定要從集合中移除的
HTMLOptionElement的零基索引的整數。如果未找到該索引,則該方法無效。
返回值
無(undefined)。
示例
html
<select id="existingList" name="existingList">
<option value="1">Option: Value 1</option>
<option value="2">Option: Value 2</option>
<option value="3">Option: Value 3</option>
</select>
js
let sel = document.getElementById("existingList");
sel.remove(1);
HTML 現在是
html
<select id="existingList" name="existingList">
<option value="1">Option: Value 1</option>
<option value="3">Option: Value 3</option>
</select>
規範
| 規範 |
|---|
| HTML # dom-select-remove |
瀏覽器相容性
載入中…
另見
Element.remove,當在HTMLSelectElement上呼叫 remove 且不帶引數時呼叫的方法。- 實現它的
HTMLSelectElement。