jquery 实现两个表格之间的数据互换?

解决方案 »

  1.   

    <!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=utf-8" />
    <title>无标题文档</title>
    <style type="text/css">
    table {
    border:1px solid #000;
    }
    </style>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
    <script type="text/javascript">
    $(document).ready( function() {
    $("#btn_switchTableData").click( function() {
    var t1 = $("#t1").children().clone();
    $("#t1").empty().append($("#t2").children());
    $("#t2").append(t1);
    });
    });
    </script>
    </head><body>
    <table id="t1">
    <tr>
         <td>AAA</td>
        </tr>
    </table>
    <table id="t2">
    <tr>
         <td>BBB</td>
        </tr>
    </table>
    <input type="button" value="互换" id="btn_switchTableData" />
    </body>
    </html>