<html>
<body>
<p>Example list:</p>
<ul>
<li id="myLI">Coffee</li>
<li>Tea</li>
</ul>
<p>单击该按钮可获取列表中 li 元素的父元素的节点名称。</p>
<button onclick="myFunction()">试一试</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myLI").parentElement.nodeName;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>