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
}
}
规范
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 |
浏览器兼容性
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!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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论