编辑下面的代码:【加编码】
<html> <body><p id="demo">Click the button get the node types of the body element's child nodes</p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { var txt=""; var c=document.body.childNodes; for (i=0; i<c.length; i++) { txt=txt + c[i].nodeType + "<br>"; }; var x=document.getElementById("demo"); x.innerHTML=txt; } </script> <p><strong>Note:</strong> Whitespace inside elements is considered as text, and text is considered as text nodes.</p> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂