运行 ❯
获取您
自身
网站
×
更改方向
保存代码
更改主题,暗/亮
前往 Spaces
<!DOCTYPE html> <html> <head> </head> <body> <h1>The HTMLCollection Object</h1> <h2>The item() Method</h2> <p>Click "Change" to change the font size of to all elements with class="myclass".</p> <button onclick="myFunction()">Change</button> <p>I am a paragraph.</p> <p class="myclass">I am a paragraph.</p> <p class="myclass">I am a paragraph.</p> <script> function myFunction() { const collection = document.getElementsByClassName("myclass"); for (let i = 0; i < collection.length; i++) { collection.item(i).style.fontSize = "24px"; } } </script> </body> </html>