zoukankan      html  css  js  c++  java
  • appendChild和insertBefore的区别

     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
     3 <head>
     4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
     5     <title></title>
     6 </head>
     7 <body>
     8     <div id="test">
     9         <p id="p1"></p>
    10         <p id="p3"></p>
    11         <p id="p4"></p>
    12     </div>
    13     <script type="text/javascript">
    14     var oTest = document.getElementById('test');
    15     var oP1 = document.getElementById('p1');
    16     var oP3 = document.getElementById('p3');
    17     var oP4 = document.getElementById('p4');
    18 
    19     var oP2 = document.createElement('p');
    20     oP2.setAttribute('id','p2');
    21     oP2.appendChild(document.createTextNode("Hello world!"));
    22 
    23     //appendChild无法设置想要插入的明确位置
    24     //oTest.appendChild(oP2);
    25 
    26     //insertBefore则可以设置
    27     //oTest.insertBefore(oP2,null);
    28     //oTest.insertBefore(oP2,oP1);
    29     //oTest.insertBefore(oP2,oP1.nextSibling);
    30     //oTest.insertBefore(oP2,oP3.previousSibling);
    31     //oTest.insertBefore(oP2,oTest.childNodes[0]);
    32     </script>
    33 </body>
    34 </html>
  • 相关阅读:
    SQL Server 文件操作
    约束5:外键约束
    SSIS 对数据排序
    列属性:RowGUIDCol、Identity 和 not for replication
    TSQL 数据类型转换
    HierarchyID 数据类型用法
    租房那些事
    SSIS 延迟验证
    SQL Server 管理全文索引
    SQL Server 全文搜索
  • 原文地址:https://www.cnblogs.com/qzsonline/p/2565856.html
Copyright © 2011-2022 走看看