【JavaScript】未來事件的處理
阿新 • • 發佈:2018-12-25
author:咔咔
wechat:fangkangfk
對於後端來說,這個知識點估計有點生
像我們後端最常使用的就是列表進行分頁,然後進行js組裝資料,在這個時候最容易發生的事就是點選事件失效。這就是因為元素都是js動態生成的,所有需要使用未來事件繫結,下面就是一個未來事件的刪除js程式碼
$(document).on('click','.del',function(){ var that = $(this), href = !that.attr('data-href') ? that.attr('href') : that.attr('data-href'); layer.confirm('刪除之後無法恢復,您確定要刪除嗎?', {title:false, closeBtn:0}, function(index){ if (!href) { layer.msg('請設定data-href引數'); return false; } $.get(href, function(res){ layer.msg(res.msg); if (res.code == 1) { that.parents('tr').remove(); } }); layer.close(index); }); return false; })