Solution to ready function conflict in JQuery _ jquery

Source: Internet
Author: User
JQuery is indeed a good framework for improving the efficiency of front-end development (although many experts say it is inefficient), 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. If multiple developers work collaboratively, the programmer John 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.

The Code is as follows:


$ (). Ready (function (){
SetTimeout (Test1, 50); // This function is executed after a delay of 50 milliseconds.
})

$ (). Ready (function (){
Test2 ();
})

Function Test1 (){
Alert (" ");
}

Function Test2 (){
Alert ("www.jb51.net ");
}


Just like this. It should have first popped up 1, then popped up 2. After triggered by latency, it became first popped up 2, then popped up 1
Related Article

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.