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

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

问题描述

有谁知道如何解除一组事件处理程序的绑定,但记住它们以便以后再次绑定它们?有什么建议吗?

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

推荐答案

item 的数据中有一个 events 元素.这应该让您开始,您可以在解除绑定之前读取您的元素并将处理程序存储在数组中.如果您需要更多帮助,请发表评论.我从阅读 $.fn.clone 方法中得到了这个想法,所以也看看那个.

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天全站免登陆