运行 ❯
获取您
的
网站
×
更改方向
保存代码
更改主题,暗/亮
转到 Spaces
<!DOCTYPE html> <html> <body> <h1>The Element Object</h1> <h2>The querySelectorAll() Method</h2> <p>Add a background color to all p elements in "myDIV":</p> <div id="myDIV" style="border:1px solid black;"> <h2>A Heading</h2> <p>A p element.</p> <p>A p element.</p> <p>A p element with class="example".</p> </div> <script> const element = document.getElementById("myDIV"); const list = element.querySelectorAll("p"); for (let i = 0; i < list.length; i++) { list[i].style.backgroundColor = "red"; } </script> </body> </html>