直接上代码
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<input type="button" value="点击" onclick="create()"/>
<table border="1">
<thead>
<tr>
<th>ID</th>
<th>姓名</th>
<th>年龄</th>
</tr>
</thead>
<tbody id="body">
</tbody>
</table>
<script>
function create() {
var tr = document.createElement("tr");
var info = {id: 1, name: "ere", age: 3434}
for (var k in info) {
var text = info[k]
var td = document.createElement("td")
td.innerText = text;
tr.appendChild(td);
}
var body = document.getElementById("body")
body.appendChild(tr)
}
</script>
</body>
</html>
就可以直接在浏览器上看到内容了。
点个赞再走呗~