Can I call $(document).ready() to re-activate all on load event handlers?

前端 未结 10 1574
情书的邮戳
情书的邮戳 2020-12-15 15:37

Does anyone happen to know IF and HOW I could re-call all on-load event handlers? I\'m referencing some .js files that I DON\'T have control over, and these .js libraries do

10条回答
  •  独厮守ぢ
    2020-12-15 15:44

    A simple way to achieve this is just to invent your own event like this:

    $(document).bind('_page_ready', function() { /* do your stuff here */});
    

    Then add this:

    $(function() { $(document).fire('_page_ready'); }); // shorthand for document.ready
    

    And last, whenever you need to run it again you simply call this:

    $(document).fire('_page_ready');
    

    [Edit]

    If you really can't edit the external script-files I've made a jsFiddle that makes what you want to do possible, you can take a look at the code here: http://jsfiddle.net/5dRxh/

    However, if you wan't to use this, it's important that you add this script RIGHT AFTER you include jQuery, like this:

    
    
    
    

提交回复
热议问题