求帮助!!!!
兄弟啊,你的“ var a=getElementsByTagName("li")”这句写错了啊,还有个document呢??!!!
<!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 a=document.getElementsByTagName("li") for(var i=0;i<a.length;i++){ document.write(a[i].nodeName+" "+a[i].nodeValue+" "+a[i].nodeType+" "); } </script> </body> </html>
for循环那里i需要定义下。
for(var i=0.....)
var a=document.getElementsByTagName("li");
<!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 a=getElementsByTagName("li")
for(i=0;i<a.length;i++)
{
document.write(a[i].nodeValue+" "+a[i].nodeType+" "+a[i].nodeName+"<br/>")
}
</script>
</body>
</html>