diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/htmlselectelement/remove/index.html | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/htmlselectelement/remove/index.html')
-rw-r--r-- | files/zh-cn/web/api/htmlselectelement/remove/index.html | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/htmlselectelement/remove/index.html b/files/zh-cn/web/api/htmlselectelement/remove/index.html new file mode 100644 index 0000000000..6cb7046a6e --- /dev/null +++ b/files/zh-cn/web/api/htmlselectelement/remove/index.html @@ -0,0 +1,94 @@ +--- +title: HTMLSelectElement.remove() +slug: Web/API/HTMLSelectElement/remove +translation_of: Web/API/HTMLSelectElement/remove +--- +<div>{{ APIRef("HTML DOM") }}</div> + +<p><code><strong>HTMLSelectElement.remove()</strong></code> 方法从一个 select 元素中删除指定序数的 option 元素。没有传参时为删除当前元素本身:<a href="/en-US/docs/Web/API/ChildNode/remove">ChildNode.remove()</a>。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><em>collection</em>.remove(<em>index</em>); +</pre> + +<h3 id="参数">参数</h3> + +<ul> + <li><code>index</code><em> </em>是从 option {{ domxref("HTMLOptionElement") }} 集合中要移除元素的序数。如果序数对应的元素不存在,调用这个方法就没有任何效果。</li> +</ul> + +<dl> +</dl> + +<h2 id="例子">例子</h2> + +<pre class="brush: js">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> +*/ +</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('HTML WHATWG', '#dom-select-remove', 'HTMLSelectElement.remove()')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName('HTML5 W3C', 'forms.html#dom-select-remove', 'HTMLSelectElement.remove()')}}</td> + <td>{{Spec2('HTML5 W3C')}}</td> + <td>Is a snapshot of {{SpecName("HTML WHATWG")}}.</td> + </tr> + <tr> + <td>{{SpecName('DOM2 HTML', 'html.html#ID-33404570', 'HTMLSelectElement.remove()')}}</td> + <td>{{Spec2('DOM2 HTML')}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName('DOM1', 'level-one-html.html#ID-33404570', 'HTMLSelectElement.remove()')}}</td> + <td>{{Spec2('DOM1')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p> + +<p>{{Compat("api.HTMLSelectElement.remove")}}</p> + +<h2 id="参考">参考</h2> + +<ul> + <li>{{ domxref("ChildNode.remove") }},当没有参数时 {{ domxref("HTMLSelectElement") }} 调用的是这个方法</li> + <li>{{domxref("HTMLSelectElement") }} 实现了这个方法。</li> +</ul> + +<p> + <audio style="display: none;"></audio> +</p> |