案例:HTML DOM案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
5
<div id="div1">
6
<p id="p1">This is a paragraph.</p>
7
<p id="p2">This is another paragraph.</p>
8
</div>
9
10
<script>
11
var para=document.createElement("p");
12
var node=document.createTextNode("This is new.");
13
para.appendChild(node);
14
15
var element=document.getElementById("div1");
16
element.appendChild(para);
17
</script>
18
19
</body>
20
</html>
21