jquery克隆问题有个tr,我想通过点击添加按钮把这个tr完整的克隆一份到这个tr的下边
并且当点及删除时能准确的将克隆的tr删除
请举个简单的例子,谢谢

解决方案 »

  1.   


    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <title>jquery克隆问题</title>
    <script type="text/javascript" src='./jpack.js'></script>
    </head>
    <body>
    <input type="button" onclick='add()' value='添加'/> <input type="button" onclick='del()' value='删除'/>
    <hr/>
    <table id='tbl' border="1" cellpadding="10" cellspacing="0">
    <tr>
    <td>自由</td>
    <td>民主</td>
    </tr>
    </table><script type='text/javascript'>
    function add() {
    $("#tbl tr:first-child").clone().prependTo("#tbl"); 
    }
    function del() {
    if ($("#tbl tr").length>1) {
    $("#tbl tr:last-child").remove(); 
    }
    }
    </script>
    </body>
    </html>