源代码:
下载代码
AI 编程工具
点击运行
<!DOCTYPE html> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> <style> .container { background-color: tomato; color: white; padding: 20px; } </style> </head> <body> <p id="myElement" class="container"></p> <script> var element = document.getElementById("myElement"); if (element.matches(".container, .wrapper")) { element.innerHTML = "元素匹配 \".container\" 或 \".wrapper\" 两个选择器中的一个。"; } else { element.innerHTML = "元素不匹配任何选择器"; } </script> </body> </html>
运行结果: