菜单切换
FACESOHO知行者
心灵
记录
远方
赞赏工具
源代码:
点击运行
保存
<!DOCTYPE html> <html> <body> <p>点击按钮修改 body 元素所有子元素的背景颜色。</p> <button onclick="myFunction()">点我</button> <h2>我是 h2 元素</h2> <div>我是 div 元素</div> <span>我是 span 元素</span> <script> function myFunction() { var c = document.body.children; var i; for (i = 0; i < c.length; i++) { c[i].style.backgroundColor = "red"; } } </script> </body> </html>
运行结果