简体   繁体   English

如何将行从第二个表移回初始表?

[英]How to move back the row from second table to initial table?

I have two tables, I move need to move rows between them. 我有两个表,我需要在它们之间移动行。 First table have add button, which adds selected items from table 1 to table two. 第一个表具有添加按钮,该按钮将表1中的选定项添加到表2中。 My add works fine and remove on the second table works but it does. 我的添加工作正常,在第二个表上删除也可以,但是可以。

My tables 我的桌子

<table id="stockForOrder" class="display">
    <thead>
        <tr>
            <th>Book Name</th>
            <th>Price</th>
            <th>ISNB</th>
            <th>Available Quantity</th>
            <th>Quantity</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>HTML5/CSS3 Fundamentals</td>
            <td>R600.00</td>
            <td>00000064</td>
            <td><input type="text" id="quantityAvaliable" 
                name="quantityAvaliable" class="form-control"
                readonly value="21" /></td>
            <td><input type="text" id="quantity"
                name="quantity" class="form-control" value="" /></td>
            <td><input class="addLineItem" type="button" 
                value="Add"></td>
        </tr>
    </tbody> 

 </table>

 <table id="toOrder" class="display">
    <thead>
        <tr>
            <th>Book Name</th>
            <th>Price</th>
            <th>ISNB</th>
            <th>Available Quantity</th>
            <th>Quantity</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody>
    <tbody>
 <table>

Java Script code Java脚本代码

   //When the button is clicked create table 2
   $(".addLineItem").on("click", function() {

       var itemsBooks = [];
       var row = $(this).closest("tr").clone();
       itemsBooks.push(row);
       row.appendTo($("#toOrder"));
       $(this).closest('tr').remove();
       $('input[type="button"]', row).removeClass('AddNew').addClass('RemoveRow').val('Remove');

   });
   //remove table 1 from table 2             
   $('table').on('click', '.RemoveRow', function(){
      $(this).closest('tr').remove();
   });
   $('#stockForOrder').on('click', '.addLineItem', function() {
   //     $(".addLineItem").on("click", function() {
        var itemsBooks = [];
        row = $(this).closest("tr").clone();
        itemsBooks.push(row);
        row.appendTo($("#toOrder"));
        $(this).closest('tr').remove();
        $('input[type="button"]', row).removeClass('AddNew').addClass('RemoveRow').val('Remove');

    });

    //remove table 1 from table 2
    $('#toOrder').on('click', '.RemoveRow', function(){
        row = $(this).closest("tr").clone();
        row.appendTo($("#stockForOrder"));
        $(this).closest('tr').remove();
        $('input[type="button"]', row).removeClass('RemoveRow').addClass('addLineItem').val('Add');
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM