Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to temporary disable the click function when it is executing?

$("#prevPage").live("click",function(e) {
.................
});

For example, when the user have already clicked on the prevPage, the statement inside it is running, if the user click on it instantly , it will trigger again. However, I would like the click event trigger only after all the statement inside it have finish execution, How to achieve that?

like image 929
user782104 Avatar asked Oct 21 '22 15:10

user782104


1 Answers

How about this or something similar:

<script type="text/javascript">
    // disable command while function is being executed.
    var sample = { 
        isExecuting : 0, 
        doWork : function (e) { 
            if (sample.isExecuting === 1) return;
            sample.isExecuting = 1;
            // do work -- whatever you please
            sample.isExecuting = 0; // say: I'm done!
        }
    };
    // live or bind
    $("#prevPage").bind("click",function(e) {
         sample.doWork(e);
    });
</script>

simple 'shield' to block a multiple-call scenario.

like image 199
Glenn Ferrie Avatar answered Oct 24 '22 12:10

Glenn Ferrie