为了账号安全,请及时绑定邮箱和手机立即绑定

用chiliNodes最后一行不能输出

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>无标题文档</title>

</head>

<body>

<div id="con">

  <p>javascript</p>

  <div>jQuery</div>

  <h5>PHP</h5>

</div>

<script type="text/javascript">

  var x=document.getElementById("con");

 document.write("div的第一个子节点是:"+x.firstChild.nodeType+"<br>");

 document.write("div的最后一个子节点是:"+x.lastChild.nodeType+"<br>");

 document.write("div的最后一个子节点是:"+x.childNodes[x.length-1].nodeType);

</script>

</body>

</html>

无法输出,浏览器编译显示nodeType未定义

正在回答

2 回答

不应该是x.length 而是 x.childNodes.length

1 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

用chiliNodes最后一行不能输出

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信