节点属性
在文档对象模型 (DOM) 中,每个节点都是一个对象。DOM 节点有三个重要的属性 :
1. nodeName : 节点的名称
2. nodeValue :节点的值
1. 元素节点的 nodeName 与标签名相同
2. 属性节点的 nodeName 是属性的名称
3. 文本节点的 nodeName 永远是 #text
1. 元素节点的 nodeValue 是 undefined 或 null
2. 文本节点的 nodeValue 是文本自身
元素类型 节点类型
元素 1
属性 2
文本 3
注释 8
节点值是:null
节点类型是:1节点名称是:LI
节点值是:null
节点类型是:1节点名称是:LI
节点值是:null
节点类型是:1
在文档对象模型 (DOM) 中,每个节点都是一个对象。DOM 节点有三个重要的属性 :
1. nodeName : 节点的名称
2. nodeValue :节点的值
3. nodeType :节点的类型
1. 元素节点的 nodeName 与标签名相同
2. 属性节点的 nodeName 是属性的名称
3. 文本节点的 nodeName 永远是 #text
4. 文档节点的 nodeName 永远是 #document
1. 元素节点的 nodeValue 是 undefined 或 null
2. 文本节点的 nodeValue 是文本自身
3. 属性节点的 nodeValue 是属性的值
三、nodeType 属性: 节点的类型,是只读的。以下常用的几种结点类型:元素类型 节点类型
元素 1
属性 2
文本 3
注释 8
文档 9
四、示例:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>节点属性</title>
</head>
<body>
<ul>
<li>javascript</li>
<li>HTML/CSS</li>
<li>jQuery</li>
</ul>
<script type="text/javascript">
var lists=document.getElementsByTagName("li");
for(var i=0;i<lists.length;
i++
){
document.write("节点名称是:"+lists[i].nodeName+"<br><br>"+"节点值是:"+lists[i].nodeValue+"<br><br>"+"节点类型是:"+lists[i].nodeType);
}
</script>
</body>
</html>
- javascript
- HTML/CSS
- jQuery
节点值是:null
节点类型是:1节点名称是:LI
节点值是:null
节点类型是:1节点名称是:LI
节点值是:null
节点类型是:1