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

May 16, 2016 pm 05:16 PM
Delayed execution

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);
}
}
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to execute a function in php after a few seconds How to execute a function in php after a few seconds Apr 24, 2022 pm 01:12 PM

Implementation method: 1. Use the "sleep (delay seconds)" statement to delay the execution of the function for several seconds; 2. Use the "time_nanosleep (delay seconds, delay nanoseconds)" statement to delay the execution of the function for several seconds and nanoseconds. ;3. Use the "time_sleep_until(time()+7)" statement.

An analysis of the causes and effects of jQuery's delayed execution An analysis of the causes and effects of jQuery's delayed execution Feb 27, 2024 pm 04:42 PM

jQuery is a popular JavaScript library that provides a wealth of functions and methods, which greatly simplifies the process of writing and programming JavaScript code. In the process of using jQuery, we often encounter situations where we need to delay the execution of certain operations. This delayed execution plays an important role in actual development. This article will explore the reasons and effects of jQuery's delayed execution, and provide specific code examples. 1. Why is it necessary to delay execution? In front-end development, sometimes we need to wait

Clever use of delayed execution of golang functions Clever use of delayed execution of golang functions Apr 25, 2024 pm 02:21 PM

The lazy execution feature of the Go language allows programmers to execute function calls after the function returns. Its main use cases include: Lazy initialization: Delay initialization of large objects or structures until needed. Post-processing: Perform cleanup or post-processing operations after the function returns. Concurrent programming: schedule background tasks to run outside the main goroutine.

Discuss the technical implementation and advantages of jQuery delayed execution Discuss the technical implementation and advantages of jQuery delayed execution Feb 28, 2024 am 08:09 AM

jQuery is a very popular JavaScript library that is widely used in web development. In the process of web development, we often encounter situations where we need to delay the execution of certain operations, and jQuery provides a variety of methods to achieve delayed execution. This article will explore the technical implementation of jQuery delayed execution and its advantages. 1. Use the setTimeout function to implement delayed execution. The setTimeout function is a timer function provided by JavaScript. It can be executed after a specified time interval.

Why does jQuery need delayed execution? Analysis and practice Why does jQuery need delayed execution? Analysis and practice Feb 27, 2024 pm 06:12 PM

Why does jQuery need delayed execution? Analysis and practice In front-end development, jQuery is a widely used JavaScript library. It simplifies DOM operations, event processing, animation effects and other functions, providing convenience for developers. However, sometimes we will find some problems, that is, under certain circumstances, jQuery needs to delay execution to achieve the desired effect. This article will analyze why jQuery requires delayed execution from both principles and practice, and provide specific code examples. one,

Master timer functions and delayed execution in JavaScript Master timer functions and delayed execution in JavaScript Nov 03, 2023 pm 04:15 PM

To master the timer function and delayed execution in JavaScript, you need specific code examples. In JavaScript, we often encounter situations where we need to execute certain codes on a scheduled basis. At this time, you need to use timer functions and delayed execution techniques to complete the task. JavaScript provides two timer functions: setInterval() and setTimeout(). The setInterval() function can repeatedly execute a piece of code at a specified time interval, while se

Analysis of the delayed execution mechanism of Golang functions Analysis of the delayed execution mechanism of Golang functions May 16, 2023 pm 12:21 PM

Golang is a widely used programming language that performs well in high-concurrency scenarios. One of its important features is the delayed execution mechanism of functions. This article will deeply explore the delayed execution mechanism of Golang functions, including the principle of delayed execution, precautions when using, etc. The principle of delayed execution The delayed execution mechanism in Golang is implemented through the defer keyword. When a function contains a defer statement, execution of the function pointed to by the statement will be deferred until the function containing the defer statement returns.

Exploration of Golang language features: resource management and delayed execution Exploration of Golang language features: resource management and delayed execution Jul 17, 2023 am 09:03 AM

Exploration of Golang language features: Resource management and delayed execution Introduction: Resource management and garbage collection are crucial aspects when developing software. As a modern programming language, Golang provides a simple and efficient resource management mechanism through its unique features. This article will explore the resource management and delayed execution features in the Golang language, and illustrate its usage and advantages through code examples. 1. Resource Management When writing software, we often need to use some resources, such as memory, file handles, network connections, etc.

See all articles