Categories: DOM对象tips

HTML DOM getAttribute() 方法 | DOM 对象:HTML DOM 元素对象

返回到:DOM 对象:HTML DOM 元素对象

定义和用法

getAttribute() 方法通过名称获取属性的值。

提示:如果你想返回属性请使用 getAttributeNode 方法。

所有主要浏览器都支持 getAttribute() 方法

语法

element.getAttribute(attributename)

参数

参数类型描述
attributenameString必须。你想获取的属性值。

返回值

类型描述
String指定属性值

技术细节

DOM 版本Core Level 1 Element Object

实例

获取链接的 target 属性值:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Web176教程网(web176.com)</title>
</head>
<body>

读取 <a href="dom_obj_attributes.php" target="_blank">Attr 对象</a>.
<p id="demo">单击按钮以显示上述链接的目标属性的值</p>
<button >
terry

这个人很懒,什么都没有留下~

Share
Published by
terry

Recent Posts