<!DOCTYPE html> <html> <body> <h1>Document 对象</h1> <h2>querySelectorAll() 方法</h2> <p>设置所有 h3、div 和 span 元素的背景颜色:</p> <h1>H1 元素</h1> <h2>H2 元素</h2> <h3>H2 元素</h3> <div>DIV 元素</div> <p>p 元素。</p> <p>一个内含 <span style="color:brown;">span</span> 元素的 p 元素。</p> <script> const nodeList = document.querySelectorAll("h3, div, span"); for (let i = 0; i < nodeList.length; i++) { nodeList[i].style.backgroundColor = "red"; } </script> </body> </html>