运行 ❯
获取您
自有
网站
×
更改方向
保存代码
更改主题,暗色/亮色
转到 Spaces
<!DOCTYPE html> <html> <body> <h1>The Element Object</h1> <h2>The contains() Method</h2> <div id="myDIV"> <p>I am a p element inside "myDIV", and I have a <span id="mySPAN"><b>span</b></span> element inside of me.</p> </div> <p>Does the div element contain a span element?</p> <p id="demo"></p> <script> const span = document.getElementById("mySPAN"); let answer = document.getElementById("myDIV").contains(span); document.getElementById("demo").innerHTML = answer; </script> </body> </html>