JavaScript获取一个节点所有属性|Node attributes 属性
定义与用法
attributes 属性返回指定节点属性的集合。
提示:
- 你可以使用 length 属性确定属性的数量,然后你可以遍历所有的属性节点提取你想要的信息。
- 每个属性都是可用属性节点对象。
语法格式
node.attributes
示例代码
获取元素属性的集合:
document.getElementsByTagName("BUTTON")[0].attributes;
浏览器支持
属性 | |||||
---|---|---|---|---|---|
attributes | Yes | Yes | Yes | Yes | Yes |
所有主要浏览器都支持 attributes 属性
提示: 在 Internet Explorer 8 以及更早的版本中,attributes 属性会返回元素所有可能属性的集合。
技术细节
返回值: | NamedNodeMap 对象, 表示属性的集合。 |
---|---|
DOM 版本 | Core Level 1 Node Object |