HTMLOptionsCollection: remove() 方法
HTMLOptionsCollection 介面的 remove() 方法從該集合中移除由索引指定的 <option> 元素。
語法
js
remove(index)
引數
index-
用於指定
HTMLOptionsCollection中HTMLOptionElement索引的零基整數。如果找不到該索引,則該方法無效。
返回值
無(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 |
瀏覽器相容性
載入中…