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/domtokenlist/add | |
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/domtokenlist/add')
-rw-r--r-- | files/zh-cn/web/api/domtokenlist/add/index.html | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/domtokenlist/add/index.html b/files/zh-cn/web/api/domtokenlist/add/index.html new file mode 100644 index 0000000000..1ce6e5da8f --- /dev/null +++ b/files/zh-cn/web/api/domtokenlist/add/index.html @@ -0,0 +1,73 @@ +--- +title: DOMTokenList.add() +slug: Web/API/DOMTokenList/add +translation_of: Web/API/DOMTokenList/add +--- +<p>{{APIRef("DOM")}}</p> + +<p>{{domxref("DOMTokenList")}} 接口的 <code><strong>add()</strong></code> 方法将给定的标记添加到列表中。 </p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><var>tokenList</var>.add(<var>token1</var>[, <var>token2</var>[, ...<var>tokenN</var>]]);</pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt>token<em>N</em></dt> + <dd>一个 {{domxref("DOMString")}},表示你要添加到列表里的标记。</dd> +</dl> + +<h3 id="返回值">返回值</h3> + +<p><code>undefined</code></p> + +<h2 id="例子">例子</h2> + +<p>在下面的例子中,我们使用 {{domxref("Element.classList")}} 将 {{htmlelement("span")}} 元素上设置的类列表检索为 <code>DOMTokenList</code>。然后,我们将新标记添加到列表中,并将列表写入 <code><span></code> 元素的{{domxref("Node.textContent")}}。</p> + +<p>HTML:</p> + +<pre class="brush: html"><span class="a b c"></span></pre> + +<p>JavaScript:</p> + +<pre class="brush: js">var span = document.querySelector("span"); +var classes = span.classList; +classes.add("d"); +span.textContent = classes; +</pre> + +<p>结果如下:</p> + +<p>{{ EmbedLiveSample('Examples', '100%', 60) }}</p> + +<p>你也可以添加多个标记:</p> + +<pre class="brush: js">span.classList.add("d", "e", "f"); +</pre> + +<h2 id="规范">规范</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('DOM WHATWG','#dom-domtokenlist-add','add()')}}</td> + <td>{{Spec2('DOM WHATWG')}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div> + + +<p>{{Compat("api.DOMTokenList.add")}}</p> +</div> |