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
|
---
title: NamedNodeMap
slug: Web/API/NamedNodeMap
translation_of: Web/API/NamedNodeMap
---
<div>{{APIRef("DOM")}}</div>
<p><code><strong>NamedNodeMap</strong></code> 介面表示了 {{domxref("Attr")}} 物件的集合。雖然 <code>NamedNodeMap</code> 與 {{domxref("NodeList")}} 都能如陣列一般透過索引訪問成員,但和 <code>NodeList</code> 不同的是,<code>NamedNodeMap</code> 中的成員並沒有順序。</p>
<p><code>NamedNodeMap</code> 物件具有<em>即時性(live)</em>,如果其內部成員(屬性節點物件)發生改變,<code>NamedNodeMap</code> 物件會自動更新至最新的狀態。</p>
<div class="note">
<p>僅管被稱作 <code>NamedNodeMap</code>,但本介面並不是直接用來處理節點物件({{domxref("Node")}}),而是專門負責屬性節點物件({{domxref("Attr")}})。屬性節點是一種特殊的節點,在部分瀏覽器實作中依然存在。</p>
</div>
<h2 id="屬性">屬性</h2>
<p><em>This interface doesn't inherit any property.</em></p>
<dl>
<dt>{{domxref("NamedNodeMap.length")}} {{ReadOnlyInline}}</dt>
<dd>Returns the amount of objects in the map.</dd>
</dl>
<h2 id="方法">方法</h2>
<p><em>This interface doesn't inherit any method.</em></p>
<dl>
<dt>{{domxref("NamedNodeMap.getNamedItem()")}}</dt>
<dd>Returns a {{domxref("Attr")}}, corresponding to the given name.</dd>
<dt>{{domxref("NamedNodeMap.setNamedItem()")}}</dt>
<dd>Replaces, or adds, the {{domxref("Attr")}} identified in the map by the given name.</dd>
<dt>{{domxref("NamedNodeMap.removeNamedItem()")}}</dt>
<dd>Removes the {{domxref("Attr")}} identified by the given map.</dd>
<dt>{{domxref("NamedNodeMap.item()")}}</dt>
<dd>Returns the {{domxref("Attr")}} at the given index, or <code>null</code> if the index is higher or equal to the number of nodes.</dd>
<dt>{{domxref("NamedNodeMap.getNamedItemNS()")}}</dt>
<dd>Returns a {{domxref("Attr")}} identified by a namespace and related local name.</dd>
<dt>{{domxref("NamedNodeMap.setNamedItemNS()")}}</dt>
<dd>Replaces, or adds, the {{domxref("Attr")}} identified in the map by the given namespace and related local name.</dd>
<dt>{{domxref("NamedNodeMap.removeNamedItemNS()")}}</dt>
<dd>Removes the {{domxref("Attr")}} identified by the given namespace and related local name.</dd>
</dl>
<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', '#interface-namednodemap', 'NamedNodeMap')}}</td>
<td>{{Spec2('DOM WHATWG')}}</td>
<td>Deals with {{domxref("Attr")}} instead of {{domxref("Node")}}</td>
</tr>
<tr>
<td>{{SpecName('DOM3 Core', 'core.html#ID-1780488922', 'NamedNodeMap')}}</td>
<td>{{Spec2('DOM3 Core')}}</td>
<td>No change from {{SpecName('DOM2 Core')}}</td>
</tr>
<tr>
<td>{{SpecName('DOM2 Core', 'core.html#ID-1780488922', 'NamedNodeMap')}}</td>
<td>{{Spec2('DOM2 Core')}}</td>
<td>Added <code>getNamedItemNS()</code>, <code>setNamedItemNS()</code> and <code>removeNamedItemNS()</code></td>
</tr>
<tr>
<td>{{SpecName('DOM1', 'core.html#ID-1780488922', 'NamedNodeMap')}}</td>
<td>{{Spec2('DOM1')}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
{{Compat("api.NamedNodeMap")}}
<h2 id="參見">參見</h2>
<ul>
<li>{{domxref("Element.attributes")}}</li>
</ul>
|