Is it safe to call $(document).ready() from inside a function?

前端 未结 3 1120
逝去的感伤
逝去的感伤 2021-01-06 01:35

If I use the $(document).ready() handler from within a function, will it still guarantee that the code inside it will only be run if the document is ready, even

3条回答
  •  醉话见心
    2021-01-06 01:51

    Yes.

    From the jQuery ready function source.

    // Catch cases where $(document).ready() is called after the
    // browser event has already occurred.
    if ( document.readyState === "complete" ) {
        // Handle it asynchronously to allow scripts the opportunity to delay ready
        return setTimeout( jQuery.ready, 1 );
    }
    

提交回复
热议问题