<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>DOM</title>
</head>
<body>
<div id="d1" align="center" class="abv">Hello DOM</div><br>
<script type="text/javascript">
var div1 = document.getElementById('d1');//获取元素节点
var as = div1.attributes;//获取旗下所有属性节点,返回数组
for(i = 0; i< as.length; i++){
document.write("<br>");
document.write(as[i].nodeName);//节点名称
document.write(" : ");
document.write(as[i].nodeValue);//节点值
}
document.write("<br>");
document.write("div的ID的属性值是:"+as["id"].nodeValue);
var content = div1.childNodes[0];//获取旗下所有子节点,其中第一个子节点就是其内容
document.write("<br>");
document.write("div的内容节点的节点名是:"+content.nodeName);
document.write("<br>");
document.write("div的内容节点的节点值是:"+content.nodeValue);
</script>
</body>
</html>
dom基础3
猜你喜欢
转载自blog.csdn.net/weixin_43293451/article/details/91410211
今日推荐
周排行