gpt4 book ai didi

javascript - 将选中的行从一个表复制到另一表

转载 作者:行者123 更新时间:2023-12-03 04:10:20 25 4
gpt4 key购买 nike

实际上,我希望将选中的行从一个 div 的表(表 1)复制到另一个 div 的表(表 2)。但是使用下面的脚本,当我检查多个复选框时,第一个检查的行将被最后检查的行替换。但我希望表 1 的每个检查行都应该一一出现在表 2 中。

任何帮助表示赞赏。提前致谢!!!

HTML

 <div class="form-group" id="jqcc" >

<table id="order-table" name="order-table">
<tr>
<th>Select</th>
<th>Medication</th>
<th>Max Issue Limit</th>
</tr>
<tbody></tbody>
</table>
</div>

Javascript

<script>
var tableControl = document.getElementById('order-table');
$('#jqcc').click(function () {
var result = []
var x1;
var tab;

var count = document.querySelectorAll('input[type="checkbox"]:checked').length;


$('input:checkbox:checked', tableControl).each(function () {

result.push($(this).parent().next().text() + "," + "<br>"); // refers title of product

$(this).closest('tr').find('input').each(function () {

x1 = $(this).val(); // refers price of product


})

tab = "<tr><td>" + result + "</td>";
tab += "<td>" + x1 + "</td>";
tab += "<td>" + x1 + " </td>";
tab += "<td><button type='button' onclick='deletePerson(this);' class='btn btn-default'> <span class='glyphicon glyphicon-remove' /></button></td>";
tab += "</tr>";
tab += "</tbody>"

$("#charges").html("<table id='peopleTable' class='table table-bordered table-condensed table-striped'><thead><tr><th>Description</th><th>Actual Amount</th> <th>Claim Amount</th> <th></th></tr></thead>" + tab + "</table>").show();

});

});
</script>

最佳答案

您尝试改变:

<script>
var tableControl = document.getElementById('order-table');
$('#jqcc').click(function () {
var result = []
var x1;
var tab = "";

var count = document.querySelectorAll('input[type="checkbox"]:checked').length;
$("#charges").html("<table id='peopleTable' class='table table-bordered table-condensed table-striped'><thead><tr><th>Description</th><th>Actual Amount</th><th>Claim Amount</th> <th></th></tr></thead><tbody></tbody></table>").show();

$('input:checkbox:checked', tableControl).each(function () {

result.push($(this).parent().next().text() + "," + "<br>"); // refers title of product

$(this).closest('tr').find('input').each(function () {

x1 = $(this).val(); // refers price of product

//
tab = "<tr><td>" + result + "</td>";
tab += "<td>" + x1 + "</td>";
tab += "<td>" + x1 + " </td>";
tab += "<td><button type='button' onclick='deletePerson(this);' class='btn btn-default'> <span class='glyphicon glyphicon-remove' /></button></td>";
tab += "</tr>";


// append row html to table with id
$("#peopleTable").append(tab);

})
});

});

关于javascript - 将选中的行从一个表复制到另一表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44360668/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com