加入子节点后,想打印出节点个数和值,但是显示不出来,什么原因??
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<ul id="test">
<li>JavaScript</li>
<li>HTML</li>
</ul>
<script type="text/javascript">
var otest = document.getElementsByTagName("ul");
var newNode=document.createElement("li");
third.innerHTML="This is a new P";
otest.appendChild(newNode);
var attr=document.getElementsByTagName("li");
document.write(attr.length);//显示长度
for(var i=0;i<attr.length;i++){
document.write(attr[i].innerHTML);
}
</script>
</body>
</html>