运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
转到 Spaces
<!DOCTYPE html> <html> <body> <h1>The Document Object</h1> <h2>The scripts Property</h2> <script id="myFirstScript"> document.write("Hello World!"); </script> <p>Display the id of each script element:</p> <p id="demo"></p> <script id="mySecondScript"> const collection = document.scripts; let text = ""; for (let i = 0; i < collection.length; i++) { text += collection[i].id + "<br>"; } document.getElementById("demo").innerHTML = text; </script> </body> </html>