JQueryTips related (1) ---- about $. Ready () _ jquery-js tutorial

Source: Internet
Author: User
The first thing to learn about jQuery is: If you want an event to run on your page, you must call this event in $ (document). ready. All elements or events included in $ (document). ready () are loaded immediately after the DOM is loaded and before the page content is loaded. I have been studying JQuery recently. This is still very broad and profound. Let's share my learning summary.

$ (Document). Ready () method VS OnLoad event VS $ (window). load () method

The first thing we learned when to get started with JQuery is when to start the event. For a long time, the events triggered after page loading were all loaded into the Onload event of the "Body.

The Onload event of the Body has many drawbacks compared with the Ready method of JQuery. For example:

1. Loading Multiple Functions

 

The Onload event can only be loaded in this way, which is ugly... In JQuery, you can use multiple JQuery. Ready () Methods to execute them in sequence.

2. The code and content are not separated.
This does not seem to have to be said, and it is so annoying -.-!!

3. Different execution sequence
For the Body. the Onload event is triggered after all the page content is loaded. I mean all the content, including images and flash. if there is a lot of such content on the page, the user will wait for a long time.

For the $ (document). ready () method, this method is triggered only after all the DOM of the page is loaded, which undoubtedly speeds up the page.

However, for some special applications, the image can be scaled in or out, and the image can be cropped. What happens after all the content on the webpage is loaded? I recommend that you use the $ (window). load () method. This method will not be triggered until all the content on the page is loaded, and there is no OnLoad event drawback.

  

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.