且构网

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

jQuery onclick删除表行

更新时间:2023-12-04 12:09:04

删除onclick并替换为一个类(即class ="remove").将事件绑定到表上-与拥有大量事件处理程序相比,这将使您获得性能提升,并确保添加的新行也将遵守此行为.

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();
});