--- title: HTMLSelectElement.remove() slug: Web/API/HTMLSelectElement/remove translation_of: Web/API/HTMLSelectElement/remove ---
HTMLSelectElement.remove()
方法从一个 select 元素中删除指定序数的 option 元素。没有传参时为删除当前元素本身:ChildNode.remove()。
collection.remove(index);
index
是从 option {{ domxref("HTMLOptionElement") }} 集合中要移除元素的序数。如果序数对应的元素不存在,调用这个方法就没有任何效果。var sel = document.getElementById("existingList"); sel.remove(1); /* 上面的代码会将下面的 select 元素结构: <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> 变成这样: <select id="existingList" name="existingList"> <option value="1">Option: Value 1</option> <option value="3">Option: Value 3</option> </select> */
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', '#dom-select-remove', 'HTMLSelectElement.remove()')}} | {{Spec2('HTML WHATWG')}} | |
{{SpecName('HTML5 W3C', 'forms.html#dom-select-remove', 'HTMLSelectElement.remove()')}} | {{Spec2('HTML5 W3C')}} | Is a snapshot of {{SpecName("HTML WHATWG")}}. |
{{SpecName('DOM2 HTML', 'html.html#ID-33404570', 'HTMLSelectElement.remove()')}} | {{Spec2('DOM2 HTML')}} | |
{{SpecName('DOM1', 'level-one-html.html#ID-33404570', 'HTMLSelectElement.remove()')}} | {{Spec2('DOM1')}} | Initial definition. |
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
{{Compat("api.HTMLSelectElement.remove")}}