當從DOM中移除元素時,jQuery-觸發器事件當一個元素從頁面中移除時,我試圖找出如何執行一些js代碼:jQuery('#some-element').remove(); // remove some element from the page/* need to figure out how to independently detect the above happened */是否有為之量身定制的活動,比如:jQuery('#some-element').onremoval( function() {
// do post-mortem stuff here});謝謝。
3 回答
GCT1015
TA貢獻1827條經驗 獲得超4個贊
(function($){
$.event.special.destroyed = {
remove: function(o) {
if (o.handler) {
o.handler()
}
}
}})(jQuery)$('.thing').bind('destroyed', function() {
// do stuff})答復Pierre和DesignerGuy評論的增編:
$('.thing').off('destroyed')if (o.handler && o.type !== 'destroyed') { ... }
- 3 回答
- 0 關注
- 835 瀏覽
添加回答
舉報
0/150
提交
取消
