A table tells you Windows.onload () and $ (document). The difference between ready () _jquery

Source: Internet
Author: User

After the browser finishes loading the DOM, events are added to the DOM elements through JavaScript, and in JavaScript, the Window.onload () method is usually used.

In jquery, the $ (document). Ready () method is used. Here are the differences between the two.

Window.onload () $ (document). Ready ()
Timing of execution Executes after all elements of the page (including pictures, reference files) are loaded.

All HTML DOM,CSS DOM structures in the page are loaded and then executed, and other pictures may not be finished loading.

If you want all content (including pictures, etc.) of the page to load, then register the event, using $ (window). Load (function);

Equivalent to Window.onload ()

Number of writes

Can not write multiple at the same time, the following will cover the front. Ex

Window.onload=function () {alert ("A");}

Window.onload=function () {alert ("B");}

The result will be "B."

If you want the sequential execution of alert ("A") and alert ("B") to be written as

Window.onload=function () {

Alert ("A");

Alert ("B");

}

Can write multiple
Shorthand No

$ (document). Ready (function () {

To do;

});

can be written

$ (). Ready (function () {//$ () with no parameters default is document

To do;

});

$ (function () {

To do;

});

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.