【问题标题】:Copy Table row to another table HTML将表格行复制到另一个表格 HTML
【发布时间】:2017-01-02 03:44:47
【问题描述】:

Fiddle

我有两张桌子。当我单击一个表格行时,它将复制到另一个表格,我将根据我的要求更改按钮。请帮我。

$(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。你为什么放 $ 符号

标签: javascript html html-table


【解决方案1】:

在你的例子中这是一个错误的选择器

$('#myTable.tr') 

而不是

$('#myTable tr')

检查固定版本:http://jsfiddle.net/V7wXD/7/

最好的问候!

【讨论】:

  • 对不起,我没有点赞,你能帮我投票吗
【解决方案2】:

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'));
    });
});

在这里测试:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-20
    • 2010-10-30
    • 1970-01-01
    相关资源
    最近更新 更多