无法在 jquery .append() 方法中的按钮中添加类或 id 以制作有效的按钮

Unable to add class or id to button in jquery .append() method to make a button that works

本文关键字:按钮 id 有效 添加 append 方法 jquery      更新时间:2023-09-26

而不是运行删除函数,我不会运行按钮类

    $("#app-table").append("<tr><td>"+sernumb+"</td><td>"+person.name1+"</td><td>"+parseInt(person.rollno)+"</td><td>"+person.address+"</td><td><button id='sideb"+r_index+"' type='button' onclick='delete_row(this);'>Delete</button></td></tr>");     // delete button to be added
    });
    $("#btn2del").click(function () {
        $("#app-table tr:last").remove();
    });
    $("#row1del").click(function () {
        $("#app-table tr:nth-child(1)").remove();  // deleting everything but the mentioned item in not
    });
    $("#delete-c").click(function(){
        alert("Its Working");
    });
});
function delete_row(ele){
       var index=$(this).parent().parent().index();
      $("#app-table tr").eq(index).remove();  // deleting current row        
}

您可以通过以下方式删除行:

function delete_row(ele){
    var parent_tr=$(this).closest('tr').remove();// deleting current row        
}