Solve ready function conflicts in jquery

Source: Internet
Author: User

Jquery is indeed a good framework to improve the efficiency of front-end development (although many experts say it is not efficient), but it is sometimes not easy to use it. You may have encountered the following situations:

 

An ASPX page can usually contain other ascx controls:ProgramClerk Zhang is in control. $ () is used in ascx (). ready (function {}), while programmer John is in control B. the ready function is also used in ascx. When Programmers Make a page. ascx, B. ascx is dragged to its own page, and $ () is also required in the page (). ready function:

 

Although jquery is still well designed, after the document is loaded, the functions defined in ready are triggered in sequence (this is good, unlike in Javascript, functions with the same name will overwrite the previous function definition by default ), but what if a programmer wants to execute his/her ready part first (or when the three programmers each have a strict order of ready processing?

 

In fact, this is not difficult. You can use setTimeout to delay the ready part of a programmer.

 

$ (). Ready (function () {setTimeout (test1, 50); // this function will be executed after a delay of 50 milliseconds}) $ (). ready (function () {Test2 () ;}) function test1 () {alert ("1") ;}function Test2 () {alert ("2 ");}

In this case, 1 should have been popped up first, and 2 should have been popped up. After a delay trigger is used, 2 will pop up first, and 1 will pop up again.

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.