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