Javascript 如何将行从第二个表移回初始表?
我有两张桌子,我需要在它们之间移动行。第一个表有add按钮,它将表1中的选定项添加到表2中。我在第二张桌子上的“添加”和“删除”都可以正常工作,但确实可以 我的桌子Javascript 如何将行从第二个表移回初始表?,javascript,html,Javascript,Html,我有两张桌子,我需要在它们之间移动行。第一个表有add按钮,它将表1中的选定项添加到表2中。我在第二张桌子上的“添加”和“删除”都可以正常工作,但确实可以 我的桌子 <table id="stockForOrder" class="display"> <thead> <tr> <th>Book Name</th> <th>Price</th>
<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>
你能描述一下你想要的行为和什么不起作用吗?必须发生的想要的行为。第一个表显示要订购的可用项目,此时用户将输入要订购的图书数量。之后,用户可以单击添加按钮将ta添加到表2中。在表2中,如果您不想订购,可以选择删除该商品。单击“删除”时,特定行将显示回初始表,即表1。删除表1上的行select以限制用户订购1次的原因。用户只能更改数量。这是我在FSFIDLE上的代码。我需要帮助的部分是,如果用户不想订购该项目,单击表2上的“删除按钮”时,将行移回初始表1。如果itemsBooks.indexOfrow.td[0]带来意外标识符错误,则这行代码。我试着把if放在花括号内,但没有运气。忽略线,不应该影响移动线。更新了我的代码。@Evelyn Ma好的,非常感谢,现在它在删除包含if语句的行后工作。
//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');
});