<html>
<body>
<h2 class="example">带有 class="example" 的标题</h2>
<p class="example">带有 class="example" 的段落。</p>
<p>单击按钮为文档中第一个 p 元素添加背景颜色,其中 class="example"。</p>
<button onclick="myFunction()">试一试</button>
<script>
function myFunction() {
document.querySelector("p.example").style.backgroundColor = "red";
}
</script>
</body>
</html>