问答详情
源自:9-13 插入节点insertBefore()

没有出来结果,不知道哪里错了....

<!DOCTYPE HTML>

<html>

<head>

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

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

</head>

<body>


<ul id="test"><li>JavaScript</li><li>HTML</li></ul> 

 

<script type="text/javascript">


  var otest = document.getElementById("test");  

  var node=document.getElementsByTagName("li").[1];

  var newnode=document.createElement("li");

  newnode.innerHTML="PHP";

  otest.insertBefore(newnode,node);

</script> 


</body>

</html>


提问者:qq_棒打孢子_0 2018-08-09 21:08

个回答

  • 慕勒6779931
    2019-06-21 10:51:02

    var otest = document.getElementById("test");  

      var sp=document.createElement('li');

      sp.innerHTML='php';

      otest.insertBefore(sp,otest.childNodes[1]);


  • 慕虎144582
    2018-09-28 11:05:43

      var otest = document.getElementById("test");  

      var new_li = document.createElement("li");

      new_li.innerHTML = "php";

      

      otest.insertBefore(new_li,otest.lastChild);


  • 慕盖茨3795866
    2018-09-06 18:21:48

    var node=document.getElementsByTagName("li").[1]中[1]前面不应该有一点.,去掉就运行出来了

  • SHFa
    2018-08-10 09:42:38

    哪里?

  • qq_棒打孢子_0
    2018-08-09 21:09:06

    a 。。。。。发现问题了....