代码示例:(标识:jsck_node_lastchild_4)
<!DOCTYPE html>
<html>
<style>
div {
  border: 1px solid black;
  margin: 15px;
}
</style>

<body>
<h1>Element 对象</h1>

<h2>lastChild 属性</h2>

<p>单击该按钮可获取 DIV 的最后一个子节点的节点名称。</p>

<div id="myDIV"><p>一个 P 元素 - div 中的第一个子节点</p><span>一个 Span 元素 - div 中的最后一个子节点</span></div>

<button onclick="myFunction()">试一试</button>

<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementById("myDIV").lastChild.nodeName;
  document.getElementById("demo").innerHTML = x; 
}
</script>

</body>
</html>
运行结果: