1
<p id="demo">单击“按钮”获取文档第一个子节点的节点名称。</p>
2
<button onclick="myFunction()">点我</button>
3
<script>
4
function myFunction() {
5
var x = document.getElementById("demo");
6
x.innerHTML = document.firstChild.nodeName;
7
}
8
</script>
<p id="demo">单击“按钮”获取文档第一个子节点的节点名称。</p>
<button onclick="myFunction()">点我</button>
<script>
function myFunction() {
var x = document.getElementById("demo");
x.innerHTML = document.firstChild.nodeName;
}
</script>