HTMLSelectElement: remove() 方法

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2015 年 7 月⁩以来,各浏览器均已提供此特性。

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

浏览器兼容性

另见