只是测试一下,尝试将表格插入到 body 标记中,但我只能使用 getElementById 来完成。我也尝试在底部插入脚本代码,但这也不起作用。
<html>
<head>
<title>Exam Test Trial</title>
<script>
var table;
var books = {1234: "Programming for Dummies", 5667: "Ethical Hacking", 88889: "Networks", 10000: "Firmware Code"};
function createTable(){
table = "<table border= '1'>";
table += "<tr>";
for(var isbn in books){
table += "<th>";
table += isbn;
table += "</th>";
}
table += "</tr>";
table += "</table>";
//var x = document.getElementById("exam").innerHTML = table;
var y;
}
</script>
</head>
<body id="exam">
<script>
createTable();
var x = document.getElementsByTagName("body").innerHTML = table;
</script>
</body>
最佳答案
getElementsByTagName("body")
返回一个类似数组的结构。您的意思是 getElementsByTagName("body")[0]
吗?
关于javascript - 为什么 getElementsByTagName 在这个逻辑中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27369805/