源代码:
下载代码
AI 编程工具
点击运行
<!DOCTYPE html> <html> <body> <p>点击按钮获取 body 元素子元素的标签名。</p> <button onclick="myFunction()">点我</button> <p id="demo"></p> <script> function myFunction() { var c = document.body.children; var txt = ""; var i; for (i = 0; i < c.length; i++) { txt = txt + c[i].tagName + "<br>"; } document.getElementById("demo").innerHTML = txt; } </script> </body> </html>
运行结果: