2017-06-05 8 views
0

Eigentlich möchte ich die überprüften Zeilen von der Tabelle eines div (Tabelle 1) in die Tabelle eines anderen div (Tabelle 2) kopieren. Aber mit dem unten stehenden Skript, wenn ich mehr als ein Kontrollkästchen ankreuze, wird die erste überprüfte Zeile durch die zuletzt geprüfte Zeile ersetzt. Aber ich möchte, dass jede überprüfte Zeile der Tabelle 1 nacheinander in Tabelle 2 erscheint.Kopieren Geprüfte Zeilen von einer Tabelle in eine andere Tabelle

Jede Hilfe wird geschätzt. Danke im Voraus!!!

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> 
+1

können Sie Ihren HTML-Code bitte hinzufügen –

Antwort

1

Sie versuchen, zu ändern:

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

    })  
}); 

});

+0

diese Lösung funktioniert, aber immer noch der Titel des Produkts mit einigen Problemen. Wenn ich das zweite Kontrollkästchen ankreuze, kommt der erste ausgewählte Checkbox-Titel auch zusammen. @le hung – Muzz

+1

Fall 1: Wenn table1 dieselbe Spalte mit table2 haben, können Sie HTML-Zeile table1 append to table2, Fall 2: Sie müssen alle var Standard in foreach –

+0

Vielen Dank @le hung – Muzz

Verwandte Themen