运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <style> .myStyle { background-color: coral; padding: 16px; } .anotherClass { text-align: center; font-size: 25px; } .thirdClass { text-transform: uppercase; } </style> <body> <h1>The DOMToken Object</h1> <h2>The contains() Method</h2> <div id="myDIV" class="myStyle anotherClass thirdClass"> <p>I am myDIV.</p> </div> <p>Does the "myDIV" element have a class of "myStyle"?</p> <p id="demo"></p> <script> let x = document.getElementById("myDIV").classList.contains("myStyle"); document.getElementById("demo").innerHTML = x; </script> </body> </html>