Table本身就有个复制的属性。

解决方案 »

  1.   

    http://www.scriptlover.com/post/389
      

  2.   

    直接复制table的outerHTml,整个table代码都出来了~~想多少拷贝就多少
      

  3.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
    <title>test</title> 
    <script>
    function f(count) {
    for (var i = 0; i < count; i ++) {
    document.body.insertAdjacentHTML("beforeEnd", document.getElementsByName("table1")[0].outerHTML);
    }
    }
    </script>
    </head> 
    <body> 
    <table id="table1" width="100" border="1">
      <tr>
        <td><input type="checkbox" />1</td>
      </tr>
      <tr>
        <td><select><option>1</option></select></td>
      </tr>
      <tr>
        <td><input type="button" value="button" /></td>
      </tr>
    </table><br />
    <input id=count type="text" style="width:20px" />
    <input type="button" value="复制" onclick="f(count.value)" /><br /><br />
    </body> 
    </html> 
      

  4.   

    你的table 的id需要改动么?
      

  5.   

    cloneNode
    <table style="background-color:#eee;margin:10px" id="tbl" border="1" >
    <tr>
    <td><input type="text" value="aaaa"/></td>
    <td><input type="text" value="bbbb"/></td>
    </tr>
    <tr>
    <td><select><option>1</option></select></td>
    <td><select><option>1</option></select></td>
    </tr>
    </table>
    <div id="copyArea">
    </div>
    拷贝次数:<input type="text" id="tNum" value="5"/><br>
    <input type="button" value="Copy(include of data)" onclick="copyTbl()"/>
    <script>
    function copyTbl()
    {
       var n = document.getElementById("tNum").value;
       var tbl = document.getElementById("tbl");
       var div = document.getElementById("copyArea");
       if(/^\d+$/.test(n))
       {
    for(var i=0;i<n;i++)
            {
       var cTbl=tbl.cloneNode(true)
       div.appendChild(cTbl);
            }
       }
    }
    </script>
      

  6.   

    那我就简洁一点:<script language="javascript">
    function copy(){
        for(var T=table1,i=eval(T1.value);(--i)>=0;)
            T.insertAdjacentElement('AfterEnd',T.cloneNode(true));
    }
    </script><table id="table1">...............</table>
    copy个数:<input type="text" id="T1" value="5">
    <input type="button" value="copy" onclick="copy()">
      

  7.   


    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
        <script type="text/javascript">
        function funCopy()
        {
            //行数 这里就不做验证了
            var count=document.getElementById("txtCount").value * 1;
            //取得tr列表
            var trlist=document.getElementById("table1").getElementsByTagName("tr");
            //清空table2表
            var t2=document.getElementById("table2");
            while(t2.hasChildNodes())
            {
                t2.removeChild(t2.firstChild);
            }
            //给table2表增加数据.
            var temp;
            for(var i=0;i<count;i++)
            {
                temp=trlist[i].cloneNode(true);
                t2.appendChild(temp);
            }
        }
        
        </script>
    </head>
    <body>
        <input id="txtCount" type="text" value="3" />
        <input id="btnCopy" onclick="funCopy();" type="button" value="button" />
        <table>
            <tbody id="table1">
            <tr>
                <td>11</td>
                <td>111</td>
            </tr>
            <tr>
                <td>22</td>
                <td>222</td>
            </tr>
            <tr>
                <td>33</td>
                <td>333</td>
            </tr>
            <tr>
                <td>44</td>
                <td>444</td>
            </tr>
            </tbody>
        </table>
        <table>
            <tbody id="table2">
            </tbody>
        </table>
    </body>
    </html>