jQuery Multiple Event Handlers - How to Cancel?

后端 未结 6 742
盖世英雄少女心
盖世英雄少女心 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:27

    If what nickf said doesn't work, you could use a small state machine:

    var trigger = 0;
    
    $(document).click(function() { 
    
      alert('a');
      if(you_want_to_return_false) {
        trigger = 1;
        return false;
      }
    });
    
    $(document).click(function() {
      if(trigger !== 0) {
      alert('b');
      } 
      trigger = 0;
    });
    

    Not the prettiest solution, but it will work.

提交回复
热议问题