getAttribute()方法

 

http://www.imooc.com/code/1587

getAttribute()方法

通过元素节点的属性名称获取属性的值。

语法:

elementNode.getAttribute(name)

说明:

1. elementNode:使用getElementById()、getElementsByTagName()等方法,获取到的元素节点。

2. name:要想查询的元素节点的属性名字

看看下面的代码,获取h1标签的属性值:

运行结果:

h1标签的ID :alink
h1标签的title :getAttribute()获取标签的属值

原文地址:https://www.cnblogs.com/superxuezhazha/p/6413923.html