The difference between the read function in jQuery and the onload function in JavaScript, jqueryonload

Source: Internet
Author: User

The difference between the read function in jQuery and the onload function in JavaScript, jqueryonload

In JavaScript, the onload function is the most frequently used, and almost all children's shoes involved in JavaScript need to access it. This function is used to execute the statements in the code block after the webpage is fully loaded. It is usually used to load JavaScript in the header according to the execution sequence of the Document Stream.

Copy codeThe Code is as follows:
Window. onload = function (){
// Execute the code block after the webpage is loaded
};

In jQuery, there is also a corresponding function, that is, the code block is executed after the webpage is loaded.
Copy codeThe Code is as follows:
$ (Document). ready (function (){
// Execute the code block after the webpage is loaded
});

The above two seemingly identical functions are actually quite different.

Onload is executed only after the DOM tree is created and all external resources are loaded and the entire page is displayed in the browser window. These resources include not only image resources, but also flash videos embedded on the page. If there are too many images or flash files, the loading takes a long time, this means that the code block execution will be delayed for more time.

In jQuery, the ready () method only needs to wait until the document structure is completely parsed and the browser has converted HTML into a DOM tree, and then runs the code block. Note that only DOM, images in webpages, flash and other external resources are unrelated.

It can be seen that the ready () method in jQuery will shorten the wait time.

Of course, there is another way to put the script behind the <body> label. In this way, the webpage will be executed in the order of document flow, which will also reach onload in JavaScript or ready () in jQuery () in this way, the webpage content is displayed faster.


The problem after the onload function is used in the body of javascript

I guess you probably used the document. write () function. This will overwrite other things.

Differences between jquery and javascript

Jquery is an extension and encapsulation of javascript, which makes javascript easier to use. What people say is jquery is to use less code to perform more functions beautifully.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.