1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> 测试测试测试 <div id="one">哈哈哈</div> <p>这是一个段落标签</p><span>这是一个span标签</span><div id="box"> <span>娃娃鱼</span> <span>托儿所</span> </div> <ul> <li>列表1</li> <li>列表2</li> <li>列表3</li> </ul> </body> </html> <script type="text/javascript"> var a1=document.body.childNodes; console.log(a1); var a2= document.querySelector("#box").parentNode; console.log(a2); console.log(document.body.firstChild); console.log(document.body.lastChild); console.log(document.querySelector("span").previousSibling); console.log(document.querySelector("span").nextSibling); console.log(document.body.children); console.log(document.querySelector("div").parentElement); console.log(document.querySelector("ul").firstElementChild); var box =document.querySelector("#box"); console.log(box.lastElementChild); console.log(box.previousElementSibling); console.log(box.nextElementSibling); console.log(box.childElementCount); </script>
|