求大神告诉我哪里错了

来源:9-9 访问子节点的第一和最后项

慕UI2712819

2016-11-03 00:58

<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(x.firstChild.nodeName+" "+x.firstChild.nodeType+" "+x.firstChild.nodeValue"<br>");

 document.write(x.lastChild.nodeName+" "+x.lastChild.nodeType+" "+x.lastChild.nodeValue"<br>");

</script>

</body>


写回答 关注

4回答

  • Hei_a
    2016-11-25 17:25:13

    +"<br>"

  • qq_浮世_4
    2016-11-21 15:28:19

    浏览器性能不同,firstChild包括了空白文本,现在普遍用的是firstElementChild和lastElementChild,这样是除了空白文本以外的内容,你可以试一试

  • stone310
    2016-11-03 01:29:08

    求人不如求己,嘎嘎

  • 慕UI2712819
    2016-11-03 01:04:18

    haha,不用了,我少打了个加号

JavaScript进阶篇

本课程从如何插入JS代码开始,带您进入网页动态交互世界

467398 学习 · 21877 问题

查看课程

相似问题