A table tells you the differences between windows. onload () and $ (document). ready () _ jquery-js tutorial

Source: Internet
Author: User
This article mainly introduces windows. onload () and $ (document ). ready () difference after the browser loads the DOM, it adds events to the DOM element through javascript. In javascript, window is usually used. onload () method.

In jquery, the $ (document). ready () method is used. The following describes the differences between the two.

Window. onload () $ (Document). ready ()
Execution time After all the elements (including images and referenced files) on the page are loaded, execute.

All html dom and css dom structures on the page are executed after they are loaded. Other images may not be loaded.

If you want to load all the content (including images) on the webpage and register the event, use $ (window). load (function );

Equivalent to window. onload ()

Write count

You cannot write multiple data records at the same time, and the subsequent data will overwrite the previous one. Ex:

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

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

The result is "B"

If you want to execute alert ("A") and alert ("B") in sequence, you must write

Window. onload = function (){

Alert ("");

Alert ("B ");

}

You can write multiple
Shorthand None

$ (Document). ready (function (){

// To do;

});

Can be written

$ (). Ready (function () {// $ () without parameters, the default value is document.

// To do;

}); Or

$ (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.