在偶数监听器块中绑定和取消绑定

时间:2015-03-10 03:21:54

标签: javascript jquery

$('.arrow').click(function(e){
    run();
    $(this).off(e); // unbind 
    setTimeout(function(){ /*rebind back*/ }, 700);   
});

如何重新绑定块本身内的click事件?我只设法关闭()点击但无法重新绑定。

1 个答案:

答案 0 :(得分:1)

命名你的回调:

$('.arrow').on("click", function cb(e){
    run();
    var $this = $(this)
    $this.off(e); // unbind 
    setTimeout(function(){ $this.on("click", cb); }, 700);   
});
像我说的那样,或者辩论它。选择你最喜欢的debounce impl,这里是underscore

$('.arrow').on("click", _.debounce(run, 700));
相关问题