Home > Web Front-end > JS Tutorial > Some methods to delay execution of JS pages (organizing)_javascript skills

Some methods to delay execution of JS pages (organizing)_javascript skills

WBOY
Release: 2016-05-16 17:16:07
Original
1398 people have browsed it

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.

Copy code The code is as follows:

//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
Copy the code The 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 = 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
Copy code The code is as follows:

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);
}
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template