DefinedSetTimeout () and setinterval () are often used to handle delays and timed tasks. The settimeout () method is used to call a function or evaluate an expression after a specified number of milliseconds, and setinterval () can loop through the function or expression at the specified number of milliseconds, until clearinterval clears it.We can see from the definition that two functions are very similar, except that the former executes once, while
.
========================================================== ==================================
========================================================== ==================================
Setinterval ("Showtime ()", 5000 );
Function Showtime (){
VaR today = new date ();
Alert ("the time is:" + today. tostring ());}
While setinterval is not bound by the function called by itself, it simply repeats the function at a certain time. ========================================================== =======
Today, I checked my website background login Detection Using JQuery + AJAX + PHP. After I found that the login was successful, I executed the page Jump function section JavaScript (JS) code effects can be executed well in IE and Google Chrome, And the compatibility is good. As a result, the JS built-in function setTimeout in FireFox is not executed. It is invalid and no error is reported! Open FireBUG and e
('OK! ')}, 1000 );} The above example is our common usage and should be easy to understand. But can timer be so accurate? Can code queue execution be so normal?[Cutting Root] re-recognize the so-called "Asynchronous"As we know, in fact, setTimeout and setInterval are simply implementing code delayed execution (or asynchronous execution) by inserting code into the code queue ). But in fact, the so-called Asynchronization is just an illusion-it also ru
() {alert (' ok! ')},1000);
}
The above example is our usual usage and should be easy to understand. But can a timer really be that accurate? is the execution of the code queue really that normal?
"Extermination" to recognize the so-called "asynchronous"
As we've just known, in fact settimeout and setinterval just simply insert code into the Code queue to implement the code's deferred execution (or asynchronous execution). But in fact the
set. When the queue is "normally" executed to the insertion point, timer callback is triggered, that is, the callback function we set:
The Code is as follows:
Function fn (){/*Here is some codes*/SetTimeout (function () {alert ('OK! ')}, 1000 );}
The above example is our common usage and should be easy to understand. But can timer be so accurate? Can code queue execution be so normal?
[Cutting Root] re-recognize the so-called "Asynchronous"
As w
When SetTimeout () and setinterval () are called to executeDefinedSetTimeout () and setinterval () are often used to handle delays and timed tasks. SetTimeout The () method is used to call a function or evaluate an expression after a specified number of milliseconds , and setinterval() can loop through a function or expression every specified number of milliseconds until clearinterval clears it.From the def
next time the process is idle. As the page life cycle progresses, the code is added to the queue in order of execution, for example, when the button is pressed, his event handlers are added to the queue and executed within the next possible time. When an AJAX response is received, the code for the callback function is added to the queue. no code in JavaScript is executed immediately, but once the process is idle it executes as soon as possible. the
the interface message.In order to solve the problem of the card, many people put forward the solution of asynchronous programming, which is also one of the ways of performance optimization, in the browser side, the long-time operation should be executed asynchronously, to avoid the browser to lose response. Now the Nodejs of the fire is asynchronous programming, such as routing, IO Operations, are asynchronous.In the front-end page implementation, the most common asynchronous is the
Encounter a problem condition:OCX reads the result set of multiple records.Use for traversal in JS.for (var i= 0;i$.ajax ({Background return resultsProcessing success,Call the method that updates the progress bar.})}found that the progress bar control is always rendered only when the for-all traversal is complete. Change the style.After reviewing n multiple data changes,Change for recursive call, do not execute once, render a progress bar, after the J
Often talk about Async, but found that they have not been in-depth understanding of settimeout, SetInterval, visit the forum when found this good article, share.———————————————————— below are the original —————————————————————————————On a basic level, it is important to understand how JavaScript timers work. The execution of timers is often different from our intuitive imagination, because the JavaScript engine is single-threaded. Let's get to know ho
time line. When a page is loaded, the method and variable declaration and data processing used after the page lifecycle are first executed. After that, the JavaScript process will wait for more code to be executed. When the process is idle, the next code is triggered.
In addition to the main JavaScript process, you also need a code queue that is executed when the process is idle for the next time. As the page lifecycle goes on, the code will be added to the queue in the execution order. For exa
on a time line. When a page is loaded, the method and variable declaration and data processing used after the page lifecycle are first executed. After that, the Javascript process will wait for more code to be executed. When the process is idle, the next code is triggered.
In addition to the main JavaScript process, you also need a code queue that is executed when the process is idle for the next time. As the page lifecycle goes on, the code will be added to the queue in the execution order. F
Today, I checked my website background login Detection Using JQuery + AJAX + PHP. After I found that the login was successful, I executed the page Jump function section JavaScript (JS) code effects can be executed well in IE and Google Chrome, And the compatibility is good. As a result, the JS built-in function setTimeout in FireFox is not executed. It is invalid and no error is reported! Open FireBUG and e
First JS delay loading
Copy Code code as follows:
In general, the use of settimeout to achieve
Second JS finally loaded
Insert the following code where you want to insert JS:
Copy Code code as follows:
Of course, that loading ... You can change your favorite small picture. It looks like an Ajax effect.
Then insert at the bottom of the page:
Copy C
If setTimeout () is used to implement recursive calling, an error will occur if the first parameter is not enclosed in quotation marks. We will share with you how to solve the problem by using setTimeout () to implement recursive calling, if the first parameter is not enclosed in quotation marks, Firefox prompts setTimeout (): uselesssetTimeout call (missing quot
Read a question about the scope of the settimeout, in fact, in the "JavaScript Advanced Programming" also saw, share to you:First summarize the following:One, the this in the deferred execution code in settimeout always points to windowSecond, SetTimeout (This.method, time) in this form, the first one mentioned above is judged by the context, which defaults to th
First part of BOM series: timer setTimeout and setInterval, bomsettimeout
SetTimeout ()
The setTimeout () method is used to specify a function or string to be executed after a specified number of milliseconds. It returns an integer indicating the timer number. This value can be passed to clearTimeout () to cancel the execution of this function.
In the following c
line. When a page is loaded, the method and variable declaration and data processing used after the page lifecycle are first executed. After that, the JavaScript process will wait for more code to be executed. When the process is idle, the next code is triggered.In addition to the main JavaScript process, you also need a code queue that is executed when the process is idle for the next time. As the page lifecycle goes on, the code will be added to the queue in the execution order. For example,
Detailed explanation of the maximum latency values of setTimeout and setInterval in JS, and setinterval latency
Preface
JavaScript provides the function of regularly executing code, called a timer.setTimeout()AndsetInterval()These two functions are complete. This article mainly introduces the problems related to the maximum latency of setTimeout and setInterval in JS. Let's take a look at them.
Let's look a
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.