jQuery Multiple Event Handlers - How to Cancel?

后端 未结 6 763
盖世英雄少女心
盖世英雄少女心 2020-12-12 23:42

I have two functions bound to a click event at two different times (using jQuery). The order in which they are fired is significant. They are firing in the correct order.

6条回答
  •  暖寄归人
    2020-12-13 00:26

    The first thing I'm asking is: why do you have two functions bound to the same click event? Having access to the code, why don't you just make that one single call?

    $(function (){
        var callbackOne = function(e){
            alert("I'm the first callback... Warning, I might return false!");
            return false;
        };
    
        var callbackTwo = function(e){
            alert("I'm the second callback");
        };
    
        $(document).click(function (e){
            if(callbackOne(e)){
                callbackTwo(e);
            }
        });
    });
    

提交回复
热议问题