<html>
<head>
<style>
div {
border: 1px solid black;
margin: 15px;
}
</style>
</head>
<body>
<p>点击按钮获取DIV最后一个子节点的节点名称。</p>
<div id="myDIV"><p>P 元素 - div 中的第一个子元素</p><span>A 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>