编辑下面的代码:【加编码】
<html> <body> <h2 class="example">class="example" 的标题</h2> <p class="example">class="example" 的段落。</p> <p>点击按钮为第一个带有 class="example" 的 p 元素添加背景颜色。</p> <button onclick="myFunction()">点我</button> <script> function myFunction() { document.querySelector("p.example").style.backgroundColor = "red"; } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂