且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

动态添加和删除表行

更新时间:2023-12-04 13:53:30

试试这个

$("#product-list").on('click','a.removerow',function(e) {
    e.preventDefault();
    //This should traverse up to the parent TR
    $(this).closest('tr').remove();
    return false;
});

这将确保可以删除新创建的元素。当你使用 $(a.removerow)时,点击(.. 它只影响存在的元素(无),而不影响将动态创建的元素。

This will ensure that newly created elements can be removed. When you use the $("a.removerow").click(.. it only affects the elements in existence (none) and not the ones that will be dynamically created.