<!DOCTYPE html> <html> <style> div { border: 1px solid black; padding: 15px; } </style> <body> <h1>Nodelist 对象</h1> <h2>length 属性</h2> <div id="myDIV"> <p>I am a paragraph.</p> <p>I am a paragraph.</p> <p>I am a paragraph.</p> </div> <p>"myDIV" 中的 p 个元素为:</p> <p id="demo"></p> <script> const div = document.getElementById("myDIV"); const list = div.querySelectorAll("p"); document.getElementById("demo").innerHTML = list.length; </script> </body> </html>