Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将选中行从一个表复制到另一个表_Javascript_Jquery - Fatal编程技术网

Javascript 将选中行从一个表复制到另一个表

Javascript 将选中行从一个表复制到另一个表,javascript,jquery,Javascript,Jquery,实际上,我希望将选中的行从一个div的表(表1)复制到另一个div的表(表2)。但在下面的脚本中,当我选中多个复选框时,第一个选中的行将替换为最后一个选中的行。但我希望表1中的每一个选中行都应该一个接一个地出现在表2中 谢谢你的帮助。提前感谢 HTML <div class="form-group" id="jqcc" > <table id="order-table" name="order-table"> <tr&

实际上,我希望将选中的行从一个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>

var tableControl=document.getElementById('order-table');
$('#jqcc')。单击(函数(){
var结果=[]
var-x1;
var选项卡;
var count=document.querySelectorAll('input[type=“checkbox”]:checked')。长度;
$('input:checkbox:checked',tableControl)。每个(函数(){
result.push($(this.parent().next().text()+”,“+”
”;//引用产品的标题 $(this).closest('tr').find('input').each(函数(){ x1=$(this).val();//表示产品的价格 }) tab=“”+结果+”; 制表符+=“”+x1+“”; 制表符+=“”+x1+“”; 制表符+=“”; 制表符+=“”; 制表符+=“” $(“#费用”).html(“描述实际金额索赔金额”+tab+).show(); }); });
您试图更改:

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

   })    
});

var tableControl=document.getElementById('order-table');
$('#jqcc')。单击(函数(){
var结果=[]
var-x1;
var-tab=“”;
var count=document.querySelectorAll('input[type=“checkbox”]:checked')。长度;
$(“#费用”).html(“说明实际金额索赔金额”).show();
$('input:checkbox:checked',tableControl)。每个(函数(){
result.push($(this.parent().next().text()+”,“+”
”;//引用产品的标题 $(this).closest('tr').find('input').each(函数(){ x1=$(this).val();//表示产品的价格 // tab=“”+结果+”; 制表符+=“”+x1+“”; 制表符+=“”+x1+“”; 制表符+=“”; 制表符+=“”; //将行html附加到id为的表中 $(“#peopleTable”)。追加(选项卡); }) });
}));

您可以添加HTML吗?此解决方案可行,但产品名称仍存在一些问题。当我选中第二个复选框时,第一个选中的复选框标题也会出现在一起@le hungcase 1:如果table1与table2有相同的列,您可以将html行table1附加到table2,案例2:您需要重置ForEachThank中的所有var默认值@le hung