案例:javascript案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<style>
5
table,th
6
{
7
border:1px solid black;
8
}
9
</style>
10
</head>
11
<body>
12
13
<table id="myTable">
14
  <tr id="myTr">
15
  </tr>
16
</table>
17
18
<h3>演示如何创建 TH 元素</h3>
19
20
<p>点击按钮来创建 TH 元素。</p>
21
22
<button onclick="myFunction()">亲自试一试</button>
23
24
<script>
25
function myFunction()
26
{
27
var x = document.createElement("TH");
28
var t = document.createTextNode("新的表头");
29
x.appendChild(t);
30
document.getElementById("myTr").appendChild(x);
31
}
32
</script>
33
34
</body>
35
</html>
36
37