Browser load mode: Window.onload and $ (document). Ready ()

Source: Internet
Author: User

The jquery library file is loaded before the BODY element and must wait for all DOM elements to load, delaying support for DOM operations, or not.

In the deferred wait load,Javascript provides an event for load, as follows:

Window.onload = function () {}; JavaScript waiting to load

$ (document). Ready (function () {}); jquery waits for load and ready differences to be loaded

Window.onload

$ (document). Ready ()

timing of execution

you have to wait for the page to finish loading (including

pictures, etc.), then execute the JS code

Just wait for the DOM structure in the Web page

loading is complete, You can execute the JS code

number of executions

can only be executed once If the second time, then

first execution will be overwritten

can execute multiple times , nth times will not be on the

overwrite

 

Shorthand scheme

No

$ (function () {})

In practical applications, window.onload is seldom used directly, as he waits for large elements such as images to be loaded before the JS code can be executed. Experience slow speed or there is a large picture to download, the page has been fully expanded, the picture is still slowly loading, then any of the page JS Interactive function in the state of suspended animation. And can only perform a single time in multiple development and team development will bring difficulties.

Write in the rear:

Hello everyone, I am currently working in the group-Kunming Branch, 2823060927 is my QQ What about Java, PHP, NodeJS, database problems can communicate with me.

Browser load mode: Window.onload and $ (document). Ready ()

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.