(2) The difference between window.load and ready

Source: Internet
Author: User

1. Timing of execution:

window.onload: You must wait for the page to complete (including images, etc.) before executing the package code

$ (document). Ready (): Just wait for the DOM structure in the Web to load and execute the package code


2. Number of executions:

window.onload: Executes only once, if the second time, then the first execution will be overwritten

$ (document). Ready (): can be executed multiple times, nth time will not be overwritten by the last time


3, abbreviated program:

window.onload: None

$ (document). Ready ():$ (function () {

});


In reality, very few use window.onload, because the large elements of the page can be loaded to execute JS code, in the case of slow speed, the page has been fully expanded but the picture is still loading, the page JS interactive function All in suspended animation state, and can only execute words in the development and team development of many times will bring some difficulties.

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.