W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <script id="w3school-1"> document.write("Hello W3School.org.cn !"); </script> <p>点击按钮遍历文档中所有的 script 元素,并输出每个 script 元素的 id。</p> <button onclick="myFunction()">点我</button> <p id="demo"></p> <script id="w3school-2"> function myFunction() { var x = document.scripts; var txt = ""; var i; for (i = 0; i < x.length; i++) { txt = txt + x[i].id + "<br>"; } document.getElementById("demo").innerHTML = txt; } </script> </body> </html>