jQuery onclick delete table row

后端 未结 5 1200
别跟我提以往
别跟我提以往 2021-01-16 14:07

How to delete table row on click?

Here is a jsfiddle.

I want to delete only row on which del link is nested, not the last row how script is doing now.

<
5条回答
  •  醉梦人生
    2021-01-16 14:41

    remove the onclick and replace with a class (ie. class="remove"). bind the event to the table - this will give you a performance gain over having lots of event handlers and make sure that new rows added will obey this behaviour too.

    $('table').on('click','tr a.remove',function(e){
      e.preventDefault();
      $(this).closest('tr').remove();
    });
    

提交回复
热议问题