<!DOCTYPE html> <html> <style> .container { background-color: tomato; color: white; padding: 20px; } </style> <body> <h1>Element 对象</h1> <h2>closest() 方法</h2> <p id="demo" class="container"></p> <script> const element = document.getElementById("demo"); let text; if (element.matches(".container, .wrapper")) { text = "该元素匹配其中一个选择器。"; } else { text = "此元素不匹配任何选择器。"; } document.getElementById("demo").innerHTML = text; </script> </body> </html>