NamedNodeMap:item() 方法
NamedNodeMap 介面的 item() 方法返回對映中與索引匹配的項。
注意: 當你使用運算子 [] 語法時,也會呼叫此方法。因此,myMap[i] 等同於 myMap.item(i),其中 i 是一個數字。
語法
js
item(index)
[index]
引數
index-
一個數字,表示要返回的項的索引。
返回值
如果該數字大於或等於對映的 length,則返回一個 Attr 或 null。
示例
html
<pre class="foo" id="bar" contenteditable></pre>
js
const pre = document.querySelector("pre");
const attrMap = pre.attributes;
pre.textContent = `The attribute map contains:
0: ${attrMap.item(0).name}
1: ${attrMap[1].name}
2: ${attrMap.item(2).name}`;
規範
| 規範 |
|---|
| DOM # dom-namednodemap-item |
瀏覽器相容性
載入中…