案例:javascript案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
5
<ul id="myList"><li>Coffee</li><li>Tea</li></ul>
6
7
<p id="demo">请点击按钮向列表中添加项目。</p>
8
9
<button onclick="myFunction()">亲自试一试</button>
10
11
<script>
12
function myFunction()
13
{
14
var node=document.createElement("LI");
15
var textnode=document.createTextNode("Water");
16
node.appendChild(textnode);
17
document.getElementById("myList").appendChild(node);
18
}
19
</script>
20
21
<p><b>注释:</b>首先创建 LI 节点,然后创建文本节点,然后把这个文本节点追加到 LI 节点。最后把 LI 节点添加到列表中。</p>
22
23
</body>
24
</html>
25