HTMLOptionsCollection: remove() 方法

HTMLOptionsCollection 接口的 remove() 方法从该集合中移除由索引指定的 <option> 元素。

语法

js
remove(index)

参数

index

用于指定 HTMLOptionsCollectionHTMLOptionElement 索引的零基整数。如果找不到该索引,则该方法无效。

返回值

无(undefined)。

示例

js
const optionList = document.querySelector("select").options;
const listLength = optionList.length;
optionList.remove(listLength - 1); // removes the last item
optionList.remove(0); // removes the first item

规范

规范
HTML
# dom-htmloptionscollection-remove-dev

浏览器兼容性

另见