运行 ❯
获取您的
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>The Element Object</h1> <h2>The hasChildNodes() Method</h2> <ul id="myList"> <li>Coffee</li> <li>Tea</li> </ul> <p>Does the list above have any child nodes?</p> <p id="demo"></p> <p>If you remove the child nodes of the list the result will be false.</p> <p><strong>Note:</strong> Whitespace between nodes is considered text nodes. If you leave any white space or line feeds, the list still has child nodes.</p> <script> let answer = document.getElementById("myList").hasChildNodes(); document.getElementById("demo").innerHTML = answer; </script> </body> </html>