问答详情
源自: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.getElementById("li");

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

  newnode.innerHTML = "PHP";

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

  

  

  

</script> 


</body>

</html>



提问者:君黙笑 2021-01-16 15:56

个回答

  • qq_慕无忌7015432
    2021-03-02 15:46:51

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

      

      var node = document.getElementById("li");

      

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

      

      newnode.innerHTML ="php";

      

      otest.insertBefore(newnode.otest.childNodes[1]);

    不知道错哪了

  • youlan_lan
    2021-02-24 15:53:48

    <!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 newnode = document.createElement("li");  newnode.innerHTML = "PHP";  otest.insertBefore(newnode,otest.lastChild);</script> </body></html>