<!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 text=document.getElementsByTagName("li");
//document.write("没错吧"+text[0].nodeVlue);
for(var i=0; i<text.length;i++){
document.write("节点的名称为:"+text[i].nodeName+"<br />"+"节点的值为:"+text[i].nodeValue+<b />+"节点的类型为:"+text[i].nodeType+<br />);
}
</script>
</body>
</html>
<script type="text/javascript">
var text=document.getElementsByTagName("li");
//document.write("没错吧"+text[0].nodeVlue);
for(var i=0; i<text.length;i++){
document.write("节点的名称为:"+text[i].nodeName+"<br />"+"节点的值为:"+text[i].nodeValue+"<br />"+"节点的类型为:"+text[i].nodeType+"<br />");
}
</script>
看我的:
<!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">
function getNodeInfo() {
var node = document.getElementsByTagName("li");
for (var i=0;i<node.length;i++) {
var nodeOne = node[i];
document.write("nodeName:" + nodeOne.nodeName + " nodeValue:" + nodeOne.nodeValue + " nodeType:" + nodeOne.nodeType + "<br>");
}
}
getNodeInfo();
</script>
</body>
</html>
值一直为null
发现了,是输出的时候<br />没加“”