案例:javascript案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
5
<p>列表示例:</p>
6
<ul><li>Coffee</li><li>Tea</li></ul>
7
8
<p id="demo">点击按钮来获得列表中首个列表项的父节点节点名。</p>
9
10
<button onclick="myFunction()">试一下</button>
11
12
<script>
13
function myFunction()
14
{
15
var x=document.getElementById("demo");  
16
var y=document.getElementsByTagName("LI")[0];
17
x.innerHTML=y.parentNode.nodeName;
18
}
19
</script>
20
21
</body>
22
</html>
23