jQuery:解除绑定事件处理程序以后再绑定它们 [英] jQuery: Unbind event handlers to bind them again later

查看:90
本文介绍了jQuery:解除绑定事件处理程序以后再绑定它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道如何取消绑定一组事件处理程序,但记住它们以便稍后再绑定?任何建议?

解决方案

该项目的数据中有一个事件元素。这应该让你的开始,你可以阅读你的元素,并将处理程序存储在数组中,然后再解除绑定。评论如果你需要更多的帮助。我从阅读$ .fn.clone方法得到这个想法,所以也看看这个。

  $(document)点击(function(e){
alert('test');
var events = $('#test' ).data(events);
$('#test')。unbind('click',events.click [0]);
});
});

< a id =test> test< / a>


Does anybody know how to unbind set of event handlers, but memorize them in order to bind them again later? Any suggestions?

解决方案

There is a events element in the data of the item. This should get your started, you can read your elements and store the handlers in an array before unbinding. Comment if you need more help. I got this idea from reading the $.fn.clone method so take a look at that as well.

$(document).ready(function() {
    $('#test').click(function(e) {
        alert('test');
        var events = $('#test').data("events");
        $('#test').unbind('click', events.click[0]);
    });
});

<a id="test">test</a>

这篇关于jQuery:解除绑定事件处理程序以后再绑定它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆