问题描述:

How to stop .click() function being fired many times if user clicks many times.

Here is my code

$("#loadme").unbind('click').click(function() {

hello();

});

If the user clicks on #loadme many times the function will repeat again and again. I want it to stop firing it many times.

网友答案:

You seem to want one :

$("#loadme").one('click', function(){
   hello();
});
网友答案:
var clicked = false;

$("#loadme").unbind('click').click(function(){
    hello();
    clicked = true;
});

function hello(){
    if(clicked){
        //do nothing because it was clicked more than once.
    }else{
        //your code
        clicked = false; //reset
    }
}
网友答案:

You can do :

$("#loadme").on("click",function(){
    $("#loadme").off("click");
    hello();
});
相关阅读:
Top