将表格行复制到另一个HTML表格

3

点此查看示例

我有两个表格。当我点击一个表格行时,它将被复制到另一个表格中,并且我可以根据需要更改按钮。请帮助我。

$(window).load(function() {
                var items = [];

                $(".addBtn").on("click", function() {
                    var newTr = $(this).closest("tr").clone();

                    var newButtonHTML = "<input type = 'button' value='Edit' onclick='Edit()' /><input type='button' value='Delete' onclick='deleteRow(this.parentNode.parentNode.rowIndex)'/>";
                    $(newButtonHTML).children("button").click(function(e) {
                    });

                    $(newTr).children("td:last").html("").html(newButtonHTML);
                    items.push(newTr);
                    newTr.appendTo($("#stopsTable"));

                });

你没有正确使用jQuery。为什么要加$符号? - chandu
2个回答

4
在您的例子中,选择器是错误的。
$('#myTable.tr') 

代替
$('#myTable tr')

请检查修复版本:http://jsfiddle.net/V7wXD/7/

最好的问候!


抱歉,我没有点赞的积分,你能给我的帖子点个赞吗? - user3547883

4

Js:

$(function() {
    $('#myTable tbody tr').each(function(){
        $(this).append('<td><button class="copy">Copy</button></td>');
    });

    $(document).on('click', 'button.copy', function(){
        var $tr = $(this).parents('tr:first').clone();

        $tr.appendTo($('#stopsTable > tbody'));
    });
});

Test here:

http://jsfiddle.net/V7wXD/8/


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接