Jquery reference: differences between $ (document). Ready () and window. onload in jquery

Source: Internet
Author: User

Window. onload = function () {alert ("welcome ");}
In this way, you want to automatically execute the defined JavaScript code after loading the page.Code(Function ).

Most of these requirementsProgramMembers will do this.

When learning jquery core functions, the $ (document). Ready (function () {...}) function is used to replace window. onload on the page;

However, $ (document) is used at startup today ). when the ready (function () {}) page (A 3 m image is used on the page), it is found that the image has not been fully loaded,

The code in function () has been executed.

The difference between shrinking the two on the Internet has found that some people have had similar experiences and have doubts (replacing window. onload means equivalent ?).

This reminds me of a sentence in jquery API.

"Allows you to bind a function to be executed when the DOM document has finished loading. "

The Chinese meaning is:

"Allows you to bind a function that is executed after the DOM document is loaded ."

Dom document loading and page loading are different, which directly shows that there is a big difference between the two.

Page loading includes at least Dom document loading (that is, the Code organization you write) and page content loading.

In this way, the difference and essence between the two are obvious.
 

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.