Home  >  Article  >  Web Front-end  >  Comparison between the execution timing of the ready() function in jquery and the load event of the window_jquery

Comparison between the execution timing of the ready() function in jquery and the load event of the window_jquery

WBOY
WBOYOriginal
2016-05-16 15:53:351055browse

jquery’s ready() implements the DOMContentLoaded event. The difference between DOMContentLoaded and window load events

To put it simply, ready() is triggered when the document is loaded. At this time, images and other resources may not be fully loaded. load is triggered after all resources are loaded

If you look at the code of the ready function, everything will be clear. The code below is commented:

// Handle when the DOM is ready
    ready: function() {
        // Make sure that the DOM is not already loaded
        if ( !jQuery.isReady ) {
            // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
            if ( !document.body ) {
                return setTimeout( jQuery.ready, 13 );
            }

            // Remember that the DOM is ready
            jQuery.isReady = true;

            // If there are functions bound, to execute
            if ( readyList ) {
                // Execute all of them
                var fn, i = 0;
                while ( (fn = readyList[ i++ ]) ) {
                    fn.call( document, jQuery );
                }

                // Reset the list of functions
                readyList = null;
            }

            // Trigger any bound ready events
            if ( jQuery.fn.triggerHandler ) {
                jQuery( document ).triggerHandler( "ready" );
            }
        }
    },

The above is the entire content of this article, I hope you all like it.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn