aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/htmlselectelement/remove/index.html
blob: 6cb7046a6e332de17df88ab72ef4b4bb9d13bb4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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 元素结构:

  &lt;select id="existingList" name="existingList"&gt;
    &lt;option value="1"&gt;Option: Value 1&lt;/option&gt;
    &lt;option value="2"&gt;Option: Value 2&lt;/option&gt;
    &lt;option value="3"&gt;Option: Value 3&lt;/option&gt;
  &lt;/select&gt;

  变成这样:

  &lt;select id="existingList" name="existingList"&gt;
    &lt;option value="1"&gt;Option: Value 1&lt;/option&gt;
    &lt;option value="3"&gt;Option: Value 3&lt;/option&gt;
  &lt;/select&gt;
*/
</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>