如何使用jQuery禁用双击或超时点击?

Sve*_*lav 1 jquery click double-click

我有一个使用jQuery .click事件的锚来启动一些功能.

jQuery(document).ready(function(){  
    jQuery('a.slide_circ').click(function(){ 
        do_all_functions();
        return false; 
    });
});
Run Code Online (Sandbox Code Playgroud)

这是简短的代码..它的工作原理,每次点击锚类slide_circ启动do_all_functions.

但我有一个问题.如果用户双击,他们运行2次或更多的功能......以及如何想法去地狱.

我认为我需要禁用双击某种方式或在我的函数上设置超时,以便每次都不运行.谁能帮我 ?

Rob*_*b W 5

使用该.data方法将状态分配给元素.然后,setTimeout用来重置状态:

jQuery(document).ready(function() {
    jQuery('a.slide_circ').click(function() { 
        var $this = jQuery(this);
        if ($this.data('activated')) return false;  // Pending, return

        $this.data('activated', true);
        setTimeout(function() {
            $this.data('activated', false)
        }, 500); // Freeze for 500ms

        do_all_functions();
        return false; 
    });
});
Run Code Online (Sandbox Code Playgroud)