案例:javascript案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
5
<h3>演示如何创建 LI 元素</h3>
6
7
<ol id="myList">
8
  <li>咖啡</li>
9
  <li>红茶</li>
10
  <li>牛奶</li>
11
  <li>橙汁</li>
12
</ol>
13
14
<p>点击按钮来创建 LI 元素。</p>
15
16
<p id="demo"></p>
17
18
<button onclick="myFunction()">试一下</button>
19
20
<script>
21
function myFunction()
22
{
23
var x = document.createElement("LI");
24
var t = document.createTextNode("豆浆");
25
x.appendChild(t);
26
document.getElementById("myList").appendChild(x);
27
}
28
</script>
29
30
</body>
31
</html>
32