【发布时间】:2014-05-03 00:25:51
【问题描述】:
我试图存储一个元素的所有事件处理程序,然后取消绑定它们,然后做一些事情然后再次绑定,但是当我取消绑定处理程序时,带有处理程序的变量被修改为一个空对象
var events = $._data(this.$element.get(0), 'events');
console.log(events); //here the variable events contains an object with the handlers
this.$element.unbind();
console.log(events); //here the variable events contains an empty object
//function to bind again the handlers
$.each(events, function() {
// iterate registered handler of original
$.each(this, function() {
$('#target').bind(this.type, this.handler);
});
});
【问题讨论】:
-
您需要复制
events对象。见stackoverflow.com/questions/728360/…