A brief analysis of the difference _javascript skills of $ (function) ready and onload

Source: Internet
Author: User

Novice contact JavaScript, jquery when the inevitable to contact the topic identified with the relevant content, repeatedly read a few times to use the time is always not practical, write this article to remember.

The symbol "$" is a jquery object (the individual understands this and has the use of the function). Then we know that the following equation is fully functional and consistent in performance.

$ (function () {/*do some thing*/}) = $ (document). Ready (function () {/* do some thing/}) = $ (). Ready (function () {/* do some Thing */});

There's something in jquery, and then next, there are window.onload and <body onload= "" > Two in native JavaScript, and there's a certain difference between using anonymous functions and not anonymous functions. I do not use it for the time being, so I did not do the experiment, the Internet is not consistent. But the onload is different from the ready in jquery, which says:

One is the number of different times, $ (). Ready () can be used multiple times in one HTML, the onload can only be used once, or the valid binding can only be the only one.

The other is the timing of the execution, simply saying that the time to execute is earlier than the onload, since $ () is executed as soon as the DOM tree is loaded, and the onload completes the execution with all the elements loaded.

The above is a small set to introduce the $ (function) ready and onload difference introduction, hope to help everyone, if you have any questions welcome to my message, small series will promptly reply to everyone, here also thank you for the cloud Habitat Community support site!

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.