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。