<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>072属性节点attributes</title>
<script>
/*
attributes 获取当前元素节点上的所有属性节点
集合:
1.无序
2.不重复
*/
window.onload=function(){
var oDiv=document.getElementById("div1");
alert(oDiv.attributes);//[object NamedNodeMap] 是一个对象属性集合
//获取其中的某一个属性节点
//title=hello
alert(oDiv.attributes.getNamedItem("title").nodeName);//title
alert(oDiv.attributes.getNamedItem("title").nodeType);//2
alert(oDiv.attributes.getNamedItem("title").nodeValue);//hello
//上面的oDiv.attributes.getNameItem("属性节点").***;比较繁琐,可以直接用以下的代替,更方便
alert(oDiv.attributes["title"].nodeName);//title
alert(oDiv.attributes["title"].nodeType);//2
alert(oDiv.attributes["title"].nodeValue);//hello
}
</script>
</head>
<body>
<div id="div1" title="hello" class="box">div文本</div>
</body>
</html>