var objDiv = document.getElementById("myCurrentDivId");
var oNewDiv = objDiv.cloneNode(true);

解决方案 »

  1.   

    <style>
    div{background-color:red;width:200px;height:200px}
    </style>
    <script>
    function set()
    {
      document.body.appendChild(document.getElementsByTagName('div')[0].cloneNode(true));
    }
    </script>
    <body>
    <div></div><input type=button value=click onclick="set()">
    </body>
      

  2.   

    请问如果我复制了多个层,那么我如何取得所有层中textbox,下拉框里面的所有的数据呢??
    期待中~~~~~~~~~~~~~~~~~~~
      

  3.   

    结合vivianfdlpw()的代码,可以实现从所有的div中取出文本框和下拉框的数据,支持多个文本框和下拉框
    <script>
    var arrayInput=new Array()
    var arraySelect=new Array()
    var arrayDiv=new Array()
    arrayDiv=document.getElementsByTagName("DIV")
    function getDivInside()
    {
      var k=0;
      var n=0;
      for(i=0;i<arrayDiv.length;i++)
        {
          for(j=0;j<arrayDiv[i].getElementsByTagName("input").length;j++,k++)
          {
            arrayInput[k]=arrayDiv[i].getElementsByTagName("input")[j].value;
          }
          for(j=0;j<arrayDiv[i].getElementsByTagName("select").length;j++,n++)
          {
            arraySelect[n]=arrayDiv[i].getElementsByTagName("select")[j].options[arrayDiv[i].getElementsByTagName("select")[j].selectedIndex].value;
          }
        }
      var str="--------------------------Input------------------------------ \n"+  
      arrayInput.join() ;
      str += "\n\n"
      str +=  "--------------------------Select------------------------------ \n" +  
      arraySelect.join();
      alert(str);
    }function set()
    {
      document.body.appendChild(arrayDiv[0].cloneNode(true));
    }
    </script>
    <style>
    div{background-color:red;width:200px;height:200px}
    </style>
    <body><input type="button" value="clone" onclick="set()">
    <input type="button" value="getIt" onclick="getDivInside()">
    <div>
    <input type="text">
    <input type="text">
    <input type="text">
    <select size=1>
    <option value='123'>123</option>
    <option value='abc'>abc</option>
    <option value='zzz'>zzz</option>
    </select>
    </div></body>
      

  4.   

    想知道 cloneNode 是不是连 ID 一起复制的?
    那不是ID重复了吗