Element.getElementsByTagNameNS() - Web API 接口参考 编辑

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
    }
}

规范

SpecificationStatusComment
DOM
Element.getElementsByTagNameNS()
Living StandardChanged the return value from NodeList to HTMLCollection.
Document Object Model (DOM) Level 3 Core Specification
Element.getElementsByTagNameNS()
ObsoleteNo change from Document Object Model (DOM) Level 2 Core Specification.
Document Object Model (DOM) Level 2 Core Specification
Element.getElementsByTagNameNS()
ObsoleteInitial definition

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!
FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support1.0[1](Yes)(Yes)[2]5.5(Yes)[1](Yes)[1]
getElementsByTagName("*")1.0(Yes)(Yes)6.0(Yes)(Yes)
FeatureAndroidEdgeFirefox Mobile (Gecko)IE PhoneOpera MobileSafari 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:132 次

字数:6687

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文