Javascript (jquery) - Multiple Handlers attached to one event: How to detach only one?

前端 未结 3 1216
野的像风
野的像风 2021-01-13 10:07

In this module I\'m working on I have a listener to a \'resize\' event in the window. Every time the module is ran, I need to check if there\'s already a listener registere

3条回答
  •  独厮守ぢ
    2021-01-13 10:44

    If you use named handlers (as opposed to anonymous functions) you can pass the name of the handler to off to remove just that one (http://api.jquery.com/off/)

    function flash() {
      $( "div" ).show().fadeOut( "slow" );
    }
    
    $( "body" ).off( "click", "#theone", flash )
    

提交回复
热议问题