HTML
CSS
JavaScript
Vue
React
Python
PHP
Java
.Net
Java9手册
PHP手册
CSS3手册
jQuery手册
源代码
在线运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(cainiaoplay.com)</title> <style>.example { border: 1px solid black; margin: 5px; } </style> </head> <body> <div class="example"> 使用 class="example" 的 div </div> <div class="example"> 另外一个使用 class="example" 的 div </div> <p class="example">使用 class="example" 的 p 元素</p> <p>这是一个使用了 class="example" 的 <span class="example">span</span> 元素,它在 p 元素里面。</p> <p>点击按钮修改所有 class="example" 元素的背景颜色。</p> <button onclick="myFunction()">点我</button> <p><strong>注意:</strong>Internet Explorer 8 及更早版本不支持 querySelectorAll() 方法。</p> <p id="demo"></p> <script> function myFunction() { var x = document.querySelectorAll(".example"); var i; for (i = 0; i < x.length; i++) { x[i].style.backgroundColor = "red"; } } </script> </body> </html>
动行结果