问答详情
源自: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 arr=document.getElementsByTagName("li")[1];
  var arr1=document.createElement("li")
   arr1.innerHTML="php"
   otest.inserBefore(arr1,arr[1]);
 
 
 
 
</script>

</body>
</html>

提问者:了吾欲前行 2016-03-23 15:33

个回答

  • thqy39
    2016-03-23 16:33:06

    <!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 arr=document.getElementsByTagName("li")[1];
      var arr1=document.createElement("li");
       arr1.innerHTML="php";
       otest.insertBefore(arr1,arr[1]);//你这里的inser,少了个"t"字母!!!拼写,平时多注意!
    </script> 
    </body>
    </html>


  • ovz_1
    2016-03-23 16:28:29

      otest.inserBefore(arr1,arr[1]);中少了"t"?insertBefore