Home  >  Article  >  Web Front-end  >  Solution to ready function conflict in JQuery_jquery

Solution to ready function conflict in JQuery_jquery

WBOY
WBOYOriginal
2016-05-16 18:27:081044browse

An aspx page can usually contain other ascx controls. If multiple people collaborate on development: programmer Xiao Zhang uses $().ready(function{}) in control A.ascx, and programmer Xiao Wang uses The ready function is also used in the control B.ascx. When the programmer Xiao Li was making the page, he dragged A.ascx and B.ascx into his own page, and then he also needed to use the $().ready function in the page. , now it’s better:

Although the design of jQuery itself is pretty good, after the document is loaded, the functions defined in each ready will be triggered in turn (this is good, unlike the default function of the same name in javascript. overwriting the previous function definition), but what if a programmer wants his own ready part to be executed first (or when the three programmers' respective ready processes are in strict order), what should we do?

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

Copy code The code is as follows:

$().ready(function(){
setTimeout(Test1, 50);//Execute this function after a delay of 50 milliseconds
})

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

function Test1(){
alert("Script Home");
}

function Test2(){
alert("www.jb51.net");
}

Just like this, Originally, 1 should pop up first, and then 2. After using the delay trigger, it will pop up 2 first, and then 1.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn