執行 ❯
建立您
自己的
網站
×
更改方向
儲存程式碼
更改主題,深色/淺色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>The Document Object</h1> <h2>The querySelectorAll() Method</h2> <p>Add a background color all elements with class="example":</p> <h2 class="example">A heading</h2> <p class="example">A paragraph.</p> <script> const nodeList = document.querySelectorAll(".example"); for (let i = 0; i < nodeList.length; i++) { nodeList[i].style.backgroundColor = "red"; } </script> </body> </html>