How to trigger $().ready() in jQuery?

前端 未结 10 1092
谎友^
谎友^ 2020-11-30 12:49

Using jQuery, is there a way to retrigger the document.ready trigger at some point after a page has loaded?

Update: jQuery sheds them once they are run.

10条回答
  •  天命终不由人
    2020-11-30 13:10

    You can do something like this:

    $(document).on('ready readyAgain', function() {
        // do stuff
    });
    
    // At some other point in time, just trigger readyAgain
    $(document).trigger('readyAgain');
    

    Note:

    $(document).on('ready') has been deprecated in jQuery 1.8 according to documentation. An alternative method is as follows:

    function myReadyFunction(){}
    $(myReadyFunction);
    
    // at some other point, just call your function whenever needed:
    myReadyFunction($);
    

提交回复
热议问题