代码示例:(标识:jsck_doc_scripts_5)
<!DOCTYPE html>
<html>
<body>
<h1>Document 对象</h1>

<h2>scripts 属性</h2>

<script id="myFirstScript">
document.write("Hello World!");
</script>

<p>显示每个脚本元素的 id:</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>
运行结果: