<!DOCTYPE html>
<html>
<head>
<style>
table, td {
border: 1px solid black;
}
</style>
</head>
<body>
<table id="myTable">
</table>
<p>单击按钮可创建一个 TR 和一个 TD 元素。</p>
<button onclick="myFunction()">试一试</button>
<script>
function myFunction() {
var x = document.createElement("TR");
x.setAttribute("id", "myTr");
document.getElementById("myTable").appendChild(x);
var y = document.createElement("TD");
var t = document.createTextNode("新单元格");
y.appendChild(t);
document.getElementById("myTr").appendChild(y);
}
</script>
</body>
</html>