这篇翻译不完整。请帮忙从英语翻译这篇文章

Element.getElementsByTagNameNS() 方法返回在指定命名空间内带有指定名称的动态HTML元素集合(而不是快照),搜索范围限定于指定元素的后代,类似于Document.getElementsByTagNameNS

语法

elements = element.getElementsByTagNameNS(namespaceURI, localName)
  • elements 是匹配元素的动态HTML元素集合HTMLCollection,其顺序为遍历树时匹配元素出现的先后。
  • element 是查找的起始结点,查找范围为该元素的后代,并且不包含该元素自身。
  • namespaceURI 是所要查询的元素的命名空间URL (参考 Node.namespaceURI). 举个例子,如果你想查找的是XHTML元素,你应该使用XHTML的命名空间URL,http://www.w3.org/1999/xhtml。
  • localName 是所要查询的元素的名称。其中特殊字符 "*" 代表所有元素 (参考 Node.localName).

示例

// 检查一个XHTML文档中表格的单元格的对齐方式。
var table = document.getElementById("forecast-table");
var cells = table.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "td");

for (var i = 0; i < cells.length; i++) {
    var axis = cells[i].getAttribute("axis");
    if (axis == "year") {
        // grab the data
    }
}

规范

Specification Status Comment
DOM
Element.getElementsByTagNameNS()
Living Standard Changed the return value from NodeList to HTMLCollection.
Document Object Model (DOM) Level 3 Core Specification
Element.getElementsByTagNameNS()
Obsolete No change from Document Object Model (DOM) Level 2 Core Specification.
Document Object Model (DOM) Level 2 Core Specification
Element.getElementsByTagNameNS()
Obsolete Initial definition

浏览器兼容性

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0[1] (Yes) (Yes)[2] 5.5 (Yes)[1] (Yes)[1]
getElementsByTagName("*") 1.0 (Yes) (Yes) 6.0 (Yes) (Yes)
Feature Android Edge Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes)[2] (Yes) (Yes) (Yes)

[1] Initially, this method was returning a NodeList; it was then changed to reflects the spec change.

[2] The behavior of element.getElementsByTagNameNS changed between Firefox 3.5 and Firefox 3.6. In Firefox 3.5 and before, this function would automatically case-fold any queries so that a search for "foo" would match "Foo" or "foo". In Firefox 3.6 and later this function is now case-sensitive so that a query for "foo" will only match "foo" and not "Foo". For more background on this, please see the comment from Henri Sivonen about the change. You can also look at the relevant part of the standard, which states which parts of the API are case-sensitive and which parts aren't.

Prior to Firefox 19, this method was returning a NodeList; it was then changed to reflects the spec change.

文档标签和贡献者

 此页面的贡献者: Topppy
 最后编辑者: Topppy,