<!DOCTYPE html> <html> <body> <h1>Document 对象</h1> <h2>querySelector() 方法</h2> <p>将背景色添加到第一个 class="example" 的 p 元素。</p> <h2 class="example">标题</h2> <p class="example">一个段落。</p> <script> document.querySelector("p.example").style.backgroundColor = "red"; </script> </body> </html>