blob: 7f1177f497f23db48c38297ca347035b71bed2d4 (
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
|
---
title: DOMTokenList
slug: Web/API/DOMTokenList
translation_of: Web/API/DOMTokenList
---
<p>{{APIRef("DOM")}}{{gecko_minversion_header("1.9.2")}}</p>
<p><code><strong>DOMTokenList</strong></code> 介面表示了一個以空格作為分隔的內容集,通常來自 {{domxref("Element.classList")}}、{{domxref("HTMLLinkElement.relList")}}、{{domxref("HTMLAnchorElement.relList")}} 或 {{domxref("HTMLAreaElement.relList")}} 等屬性。本介面與 {{jsxref("Array")}} 同樣是由 <code>0</code> 開始索引,且 <code>DOMTokenList</code> 是區分大小寫的。</p>
<h2 id="屬性">屬性</h2>
<p><em>This interface doesn't inherit any property.</em></p>
<dl>
<dt>{{domxref("DOMTokenList.length")}} {{ReadOnlyInline}}</dt>
<dd>Is an <code>integer</code> representing the number of objects stored in the object.</dd>
</dl>
<h2 id="方法">方法</h2>
<p><em>This interface doesn't inherit any method.</em></p>
<dl>
<dt>{{domxref("DOMTokenList.item()")}}</dt>
<dd>Returns an item in the list by its index (or undefined if the number is greater than or equal to the length of the list, prior to {{gecko("7.0")}} returned null)</dd>
<dt>{{domxref("DOMTokenList.contains()")}}</dt>
<dd>Returns <code>true</code> if the underlying string contains <em>token</em>, otherwise <code>false</code></dd>
<dt>{{domxref("DOMTokenList.add()")}}</dt>
<dd>Adds <em>token</em> to the underlying string</dd>
<dt>{{domxref("DOMTokenList.remove()")}}</dt>
<dd>Removes <em>token</em> from the underlying string</dd>
<dt>{{domxref("DOMTokenList.replace()")}}</dt>
<dd>Replaces an existing <em>token</em> with a new token.</dd>
<dt>{{domxref("DOMTokenList.supports()")}}</dt>
<dd>Returns <code>true</code> if a given <em>token</em> is in the associated attribute's supported tokens.</dd>
<dt>{{domxref("DOMTokenList.toggle()")}}</dt>
<dd>Removes <em>token</em> from string and returns false. If <em>token</em> doesn't exist it's added and the function returns true</dd>
</dl>
<h2 id="規範">規範</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName("DOM WHATWG", "#interface-domtokenlist", "DOMTokenList")}}</td>
<td>{{Spec2("DOM WHATWG")}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
{{Compat("api.DOMTokenList")}}
<h2 id="參見">參見</h2>
<ul>
<li>{{domxref("DOMSettableTokenList")}} (object that extends DOMTokenList with settable <em>.value</em> property)</li>
</ul>
|