正在将所选行传输到另一个表

Transferring selected row to another table

本文关键字:传输 另一个      更新时间:2023-09-26

我从数据库中提取数据,并将其显示在带有复选框的表中。我想做的是,所选的行应该移动到第二个表中,我不希望复选框列出现在第二个表格中

 <table class="table">
    <tr>
        <th></th>
        <th>Business Identifier</th>
        <th>Site Name</th>
        <th>City</th>
        <th>Postcode</th>
    </tr>
    @if (Model.UserAccountSummary != null && Model.UserAccountSummary.Any())
    {
        foreach (var item in Model.UserAccountSummary)
        {
            <tr>
                <td>
                   <input name="Id" type="checkbox" value="@item.business_customer_identifier" class="chkclass"></td>
                <td>@Html.DisplayFor(modelItem => item.business_customer_identifier)</td>
                <td>@Html.DisplayFor(modelItem => item.customer_name)</td>
                <td>@Html.DisplayFor(modelItem => item.postal_town)</td>
                <td>@Html.DisplayFor(modelItem => item.postcode)</td>
            </tr>
        }
    }
</table>

这是JS代码:

$().ready(function () {
        $(".table").on("click", ".chkclass", function () {
            if ($(this).is(":checked")) {
                var trItem = $(this).closest("tr").clone();
                trItem.add("<tr>").append("</tr>");
                $("#targetTable").append(trItem);
            }
        });
    });
$(function () {
    $(".table").on("click", ".chkclass", function () {
        if ($(this).is(":checked")) {
            $(this).closest("tr").appendTo("#targetTable");
        }
    });
});

试试这个:

$(document).ready(function(){
    $().ready(function () {
        $(".table").on("click", ".chkclass", function () {
            if ($(this).is(":checked")) {
                var trItem = $(this).closest("tr").clone();
             trItem.find("input").remove();
                trItem.add("<tr>").append("</tr>");
                $("#targetTable").append(trItem);
            }
        });
    });
});

以下是用于将记录从一个表复制到另一个表的JS代码,而无需在目标表中选择复选框:

  $(document).ready(function () {
        $().ready(function () {
            $(".table").on("click", ".chkclass", function () {
                if ($(this).is(":checked")) {
                    var trItem = $(this).closest("tr").clone();
                    trItem.find("input").remove();
                    trItem.add("<tr>").append("</tr>");
                    $("#targetTable").append(trItem);
                }
            });
        });
    });