此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

HTMLSelectElement:remove() 方法

基线 广泛可用

自 2015年7月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

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

浏览器兼容性

参见