Compare Body.onload (function ()), $ (document). Ready (function ()) and $ (Windows). Load (function)

Source: Internet
Author: User

principle Comparison :

Body.onload (function ()) is a priority to render the DOM of the document, the page will be all the elements (including HTML tags and the referenced image, Flash media and other media files) to complete the loading, and then execute the page script;

$ (Windows). Load (function ()) has the same effect as body.onload (function ()).

$ (document). Ready (function ()) is a priority to load the document structure (excluding non-text media files such as pictures), which is to load the HTML DOM first and then execute the script.

★$ (document) instance of Ready (function ())

<script src="js/jquery-1.7.2.min.js"></script>    <script>         function MyFunction () {            $ ("#test"). HTML ("Changed " )        }        $ (document). Ready (myFunction);         /* $ (document). Ready () is preferred to load the document structure (not including pictures and other non-text media files), do not have to wait until all the loaded */    </SCRIPT><H1 id="test">Original

★$ (document) instance of Ready (function ()) 2

★$ (window). Instance of Load (function ())

/*$ (window). Load (function) is executed after all elements of the page (including HTML tags and all images, Flash, and other media) have been loaded and executed in the same order as body.onload (function). */$ (window). Load (function () {alert ("Hello");        }); /*set two load (function) in parallel*/$ (window). Load (function () {alert ("See you again!")        })        /*$ (window). Load (function) is executed after all elements of the page (including HTML tags and all images, Flash, and other media) have been loaded and executed in the same order as body.onload (function). */

Example of Body.onload (function ())

Compare Body.onload (function ()), $ (document). Ready (function ()) and $ (Windows). Load (function)

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.