Reset jQuery one() so that it will fire again

后端 未结 2 725
轻奢々
轻奢々 2020-12-11 06:51

I\'m using the jQuery one() method on an event handler to fire once then de-register itself. Something like:

$(\".main\").one(\'mousedown\', \'.         


        
2条回答
  •  情歌与酒
    2020-12-11 07:42

    I would recommend wrapping the one() method bind inside a function call, then you can call the function (to bind the initial event handlers) on page load, and again on success of the Ajax call.

    var bindEvents = function(){
      $(".main").one('mousedown', '.resizeBar', function (e) { /* my code */ });
    };
    
    $(function(){ bindEvents(); }); // call the one() method on page load.
    
    $.post(pageURL, function(data){
      bindEvents(); // As an example, after some sort of Ajax or post-reset event.
    });
    

提交回复
热议问题