HTML DOM
HTMLSelectElement.remove() 方法会从 select 元素的 options 集合中移除指定索引处的元素。
语法
remove(index)
参数
index- : 一个从零开始的整数,表示要从集合中移除的 HTMLOptionElement 的索引。如果未找到该索引,则此方法不会产生任何效果。
返回值
无(undefined)。
示例
<select id="existingList" name="existingList">
<option value="1">选项:值 1</option>
<option value="2">选项:值 2</option>
<option value="3">选项:值 3</option>
</select>
let sel = document.getElementById("existingList");
sel.remove(1);
现在的 HTML 是:
<select id="existingList" name="existingList">
<option value="1">选项:值 1</option>
<option value="3">选项:值 3</option>
</select>
规范
浏览器兼容性
参见
- Element.remove,当在 HTMLSelectElement 上调用无参数的 remove 时,会调用的对应方法。
- 实现该接口的 HTMLSelectElement。
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
