HTMLSelectElement:remove() 方法
>HTMLSelectElement.remove() 方法会从 select 元素的 options 集合中移除指定索引处的元素。
语法
js
remove(index)
参数
index-
一个从零开始的整数,表示要从集合中移除的
HTMLOptionElement的索引。如果未找到该索引,则此方法不会产生任何效果。
返回值
无(undefined)。
示例
html
<select id="existingList" name="existingList">
<option value="1">选项:值 1</option>
<option value="2">选项:值 2</option>
<option value="3">选项:值 3</option>
</select>
js
let sel = document.getElementById("existingList");
sel.remove(1);
现在的 HTML 是:
html
<select id="existingList" name="existingList">
<option value="1">选项:值 1</option>
<option value="3">选项:值 3</option>
</select>
规范
| 规范 |
|---|
| HTML> # dom-select-remove> |
浏览器兼容性
参见
Element.remove,当在HTMLSelectElement上调用无参数的 remove 时,会调用的对应方法。- 实现该接口的
HTMLSelectElement。