我无法使用jQuery删除行 [英] I cannot remove row with jQuery

查看:113
本文介绍了我无法使用jQuery删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在发票表中单击添加新行"时,它会动态添加行.

When I click 'add new row' to my invoice table, it dynamically adds the row.

但是,当我必须使用删除行"按钮动态删除该行时,它不会删除.

However when I have to delete the row dynamically with the 'remove row' button it does not delete.

有什么想法可以解决此问题吗?

Any ideas how this can be fixed?

下面是我的代码:

<tbody class="body">
    <tr>
        <td><input type="hidden" class="form-control" name="count[]" value="1"><span>1</span</td>
        <td><input type="text" class="form-control" name="item[]" placeholder="item"/></td>
        <td><input type="text" class="form-control" name="description[]" placeholder="description"/></td>
        <td><input type="text" class="form-control quantity" name="quantity[]" placeholder="quantity"/></td>
        <td><input type="text" class="form-control price" name="price[]" placeholder="price"/></td>
        <td><input type="text" class="form-control item_discount" name="item_discount[]" value="0" placeholder="item discount"/></td>
        <td><input type="text" class="form-control total" name="total[]" placeholder="total" readonly=""/></td>
    </tr>
</tbody>

<div class="col-md-6">
    <button type="button" class="btn btn-success" id="add-row"><i class="fa fa-plus"> Add new row</i></button>
    <button type="button" class="btn btn-danger" id="remove-row"><i class="fa fa-minus"> Remove row</i></button>
</div>

$('#remove-row').click(function() {
    $(this).parents().first().remove();
});

谢谢.

推荐答案

如果将新行添加到表的末尾,请执行以下操作

If your new row gets added to the end of your table do the following

$( 'tbody tr:last-child' ).remove();

如果要删除表格的第一行,则需要执行以下操作

If you are removing the first row of your table you will need to do the following

$( 'tbody tr:first-child' ).remove();

这篇关于我无法使用jQuery删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆