HTML DOM Element getAttribute() 方法

HTML DOM Element getAttribute() 方法

HTML DOM Element getAttribute() 方法

focus()

getAttributeNode()

HTML DOM Elements 对象

定义和用法

getAttribute() 方法返回元素属性的值。

实例

例子 1

获取元素的 class 属性值:

let text = element.getAttribute("class");

亲自试一试

例子 2

获取 元素的 target 属性的值:

let text = myAnchor.getAttribute("target");

亲自试一试

例子 3

获取