Generally, some methods are delayed in JS pages. You can use the following method
JQuery.delay() method introduction
http://shawphy.com/2010/11/jquery-delay.html
Usage of queue and dequeue in jQuery
http://www.jb51.net/article/25481.htm
Window.setTimeout
http://www.jb51.net/article/20741.htm
Here are some examples I use.
//Delayed query, pass an ID to query btn, Then according to its nearby FORM binding, when the control in the FORM is triggered or input, it will simulate clicking the query button 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();
}
Define the mask layer and close it after one minute
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 = img;
div = "
";
var $body = $("body");
$body.prepend(div);
}
$layerMask. show();
//Cancel after 1 minute
hideTimeout = setTimeout(hideLayerMask,60000);
}
function hideLayerMask(){
if(hideTimeout != null){
clearTimeout(hideTimeout);
}
$layerMask = $(".layerMask");
$layerMask.hide();
}
Countdown
var emailTime = 30;
function nextCanDo(){
$("#mailValidateCodeBtn").val(emailTime "seconds");
emailTime -= 1;
if(emailTime ==0 ){
$("#mailValidateCodeBtn").val( "Reget verification code");
$("#mailValidateCodeBtn").attr("disabled",false);
emailTime = 30;
}else{
setTimeout("nextCanDo() ",1000);
}
}