Removing events in jquery
I have some code in jquery which looks like this:
$("#filterZaal").attr("disabled", "disabled");
$("#filterGenre").attr("disabled", "disabled");
$("#filterZaal").live("change", interceptZaalFilter);
$("#filterDag").live("change", interceptDagFilter);
$("#filterGenre").live("change", interceptGenreFilter);
Now, i have added a button, and when i push this button开发者_如何转开发 i would like that all of the above code does not count anymore, so when i push the button, these events would no longer be called but when i push it again it should become enabled again.
How can i do this in jquery?
Rather than add/remove the events each time with die(), I'd just create a toggle flag:
var Toggle = false;
$("#filterZaal").live("change", function(){ 
  if(Toggle){ interceptZaalFilter(); }   // alterantively, add this check
  Toggle = !Toggle;                      // to the func you call
});
// and so on
This seems to better capture what you want, and will almost certainly be more efficient.
have the event handlers check if $('#theButton').hasClass('disabled') and if so, they do $('#theButton').removeClass('disabled') and return false; else proceed normally
then when you add the button make sure it has a 'disabled' class
You'll want to use die():
$("#filterZaal").die("change", interceptZaalFilter);
$("#filterDag").die("change", interceptDagFilter);
$("#filterGenre").die("change", interceptGenreFilter);
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论