这一节的答案提交不了啊,强迫症受不了!
var x=document.getElementsByTagName("li"); for(i=0;i<x.length;i++){ var name=x[i].nodeName; document.write(name+";"); var value=x[i].nodeValue; document.write(value+";"); var type=x[i].nodeType; document.write(type+";"); }
2015-11-28
<!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 arr1 = document.getElementsByTagName("li"); for(var i = 0;i<arr1.length;i++){ document.write("节点名称"+(i+1)+ ":"+arr1[i].nodeName+"</br>"); document.write("节点值"+(i+1)+ ":"+arr1[i].nodeValue+"</br>"); document.write("节点类型"+(i+1)+ ":"+arr1[i].nodeType+"</br>"); } //可以通过 </script> </body> </html>
举报