Element:getElementsByTagNameNS() 方法
Element.getElementsByTagNameNS() 方法返回一個對給定名稱空間中具有給定標籤名稱的元素的即時 HTMLCollection。它與 Document.getElementsByTagNameNS 類似,但其搜尋僅限於指定元素的後代。
語法
js
getElementsByTagNameNS(namespaceURI, localName)
引數
namespaceURI-
要查詢的元素的名稱空間 URI(請參閱
Element.namespaceURI和Attr.namespaceURI)。例如,如果您需要查詢 XHTML 元素,請使用 XHTML 名稱空間 URIhttp://www.w3.org/1999/xhtml。 localName-
要查詢的元素的本地名稱,或者特殊值
"*",它匹配所有元素(請參閱Element.localName和Attr.localName)。
返回值
一個動態的 HTMLCollection,包含了按在樹中出現的順序排列的已找到的元素。
示例
js
// Check the alignment on a number of cells in a table in an XHTML document.
const table = document.getElementById("forecast-table");
const cells = table.getElementsByTagNameNS(
"http://www.w3.org/1999/xhtml",
"td",
);
for (const cell of cells) {
const axis = cell.getAttribute("axis");
if (axis === "year") {
// Grab the data
}
}
規範
| 規範 |
|---|
| DOM # dom-element-getelementsbytagnamens |
瀏覽器相容性
載入中…