0
我试图存储一个元素的所有事件处理程序,然后解开它们,然后做一些事情,然后再次绑定,但通常处理程序的变量被修改为当我取消绑定处理空对象解除绑定所有事件处理程序,做一些事情,然后再绑定jquery
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'对象的副本。请参阅http://stackoverflow.com/questions/728360/most-elegant-way-to-clone-a-javascript-object – Barmar