Onload execution sequence

Source: Internet
Author: User

Today I have studied the sequence of onload event execution for window objects,

First, add

<Body> <SCRIPT> alert ('body inlined load'); </SCRIPT> </body>

Then add

<SCRIPT type = "text/JavaScript" src = "./J. js"> </SCRIPT>

The content of J. JS is as follows:

$ (Function (){

Alert ('document init ');

$ (Window). BIND ('load', function (){

Alert ('Bind load ');

});

});

Window. onload = function (){

Alert ('onload ');

}

$ (Function (){

Alert ('document init2 ');

$ (Window). BIND ('load', function (){

Alert ('Bind load2 ');

});

});

The final execution sequence should be

Body inlined Load

Document init

Document init2

Onload

Bind Load

Bind load2

It can be seen that the code written directly to the closest to the body is the first to be executed, followed by the code in jquery's ready function, and then loaded through the window. the code in the onload processing function is finally bound to the processing code through the jquery bind function. If you need to wait until all the elements in the page are loaded before execution, you may specify the window. onload = function () {} or through jquery. bind binding, this is the best thing!

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.