Generally, some methods are executed at the JS page latency. You can use the following methods
JQuery. delay () method Overview
Http://shawphy.com/2010/11/jquery-delay.html
Queue and dequeue usage in jQuery
Http://www.jb51.net/article/25481.htm
Window. setTimeout
Http://www.jb51.net/article/20741.htm
Here are some examples I have used.
Copy codeThe Code is as follows:
// Delayed query: Upload a btn ID for query, and bind it to the FORM near it. When the control in the FORM is triggered or entered, the query button will be clicked after 500 milliseconds.
Var timeout;
Function searchTrigerInit (btnId ){
Var $ form = $ ("#" + btnId). closest ("form ");
$ Form. find ("input"). not (". search_onblur"). keyup (function (){
SearchTriger (btnId );
});
$ Form. find ("input. search_onblur"). blur (function (){
SearchTriger (btnId );
});
$ Form. find ("input [type = checkbox]"). change (function (){
SearchTriger (btnId );
});
$ Form. find ("select"). change (function (){
SearchTriger (btnId );
});
}
Function searchTriger (btnId ){
If (timeout! = Null ){
ClearTimeout (timeout );
}
Timeout = setTimeout ("searchBtnClick ('" + btnId + "')", 500 );
}
Function searchBtnClick (btnId ){
$ ("#" + BtnId). click ();
}
Defines the mask layer, which is closed after one minute
Copy codeThe Code is as follows:
Var hideTimeout;
Function showLayerMask (){
$ LayerMask = $ (". layerMask ");
If ($ layerMask. length = 0 ){
Var div = "";
Var width = document. body. clientWidth;
Var Height = document. body. scrollHeight;
Var img = " ";
Div + = "<div class = 'layermask' style = 'width: 100%; height:" + Height + "px; '> ";
Div + = img;
Div + = "</div> ";
Var $ body = $ ("body ");
$ Body. prepend (div );
}
$ LayerMask. show ();
// Cancel in 1 minute
HideTimeout = setTimeout (hideLayerMask, 60000 );
}
Function hideLayerMask (){
If (hideTimeout! = Null ){
ClearTimeout (hideTimeout );
}
$ LayerMask = $ (". layerMask ");
$ LayerMask. hide ();
}
Countdown
Copy codeThe Code is as follows:
Var emailTime = 30;
Function nextCanDo (){
$ ("# MailValidateCodeBtn"). val (emailTime + "second ");
EmailTime-= 1;
If (emailTime = 0 ){
$ ("# MailValidateCodeBtn"). val ("retrieve verification code again ");
$ ("# MailValidateCodeBtn"). attr ("disabled", false );
EmailTime = 30;
} Else {
SetTimeout ("nextCanDo ()", 1000 );
}
}