NamedNodeMap: phương thức getNamedItem()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Phương thức getNamedItem() của giao diện NamedNodeMap trả về Attr tương ứng với tên đã cho, hoặc null nếu không có thuộc tính tương ứng.
Note:
Phương thức này cũng được gọi khi bạn sử dụng cú pháp toán tử []. Vì vậy, myMap[str] tương đương với myMap.getNamedItem(str) khi str là một chuỗi.
Cú pháp
js
getNamedItem(name)
[name]
Tham số
name-
Một chuỗi với tên của thuộc tính mong muốn.
Giá trị trả về
Một Attr tương ứng với name được truyền vào tham số, hoặc null nếu không tìm thấy.
Ví dụ
html
<pre test="test"></pre>
js
const pre = document.querySelector("pre");
const attrMap = pre.attributes;
const value = attrMap.getNamedItem("test").value;
pre.textContent = `The 'test' attribute contains ${value}.
And 'foo' has ${attrMap["foo"] ? "been" : "not been"} found.`;
Thông số kỹ thuật
| Specification |
|---|
| DOM> # dom-namednodemap-getnameditem> |