SetTimeout ()
The settimeout () method is used to specify that a function or string is executed after a specified number of milliseconds. It returns an integer that represents the number of the timer, which can be passed to Cleartimeout () to cancel the execution of this function
In the following code, the console first outputs 0, probably over 1000ms or 1s, the output timer
the delay
--------------------------------------------------------------------------------
SetInterval () This function is the same as setttimeout, but also delay execution, but with settimeout () is not the same place, settimeout execution stopped, and SetInterval will continue to carry out ...
1. settimeout ()
1.1
See a good article "you will use SetTimeout", reprinted over, changed a name, suddenly feel big, quack.
Added a few small knowledge about settimeout and setinterval:
About SetInterval () and settimeout () return values
SetInterval (), settimeout () returns a value that is generally considered to be an ID, passing th
Using settimeout () to implement recursive invocation, if the first argument is not quoted, Firefox prompts SetTimeout (): Uselesssettimeout call (missing quotes around?) If you add quotes, Firefox prompts that function undefined
function Refreshnum () {
$.ajax ({
type: POST),
URL: "Ajax/refreshnum.ashx",
asyn
。 (Novice may think that settimeout and setinterval are JavaScript functions, which is wrong.) Beginners can easily confuse JavaScript object functions with Dom object methods. )
First a piece of code, you can guess what the results will be in various browsers?
Copy Code code as follows:
function f () {
var s = ' arguments.length: ' +arguments.length+ '; ';
for (var i=0,n=arguments.length;is + + ' [' +i+ ']: ' +arguments[i]+ '; ';
When setTimeout is executed, it executes expression 1 at a specified time after loading. Basic usage: run a piece of code: vari0; setTimeout ( quot; I + 1; alert (I) quot;, 1000); execute a function: vari0; setTimeout (function () {I + 1; ale...
When setTimeout is executed, it executes expression 1 at a specified tim
. (New users may think that setTimeout and setinterval are JavaScript Functions, which is incorrect. Beginners can easily confuse JavaScript Object functions with DOM object methods .)
FirstCodeLet's guess what the results will look like in various browsers?Copy codeThe Code is as follows: function f (){VaR S = 'arguments. Length: '+ arguments. Length + ';';For (VAR I = 0, n = arguments. length; I S + = '[' + I + ']:' + arguments [I] + ';';}Alert
SetInterval () and setTimeout () must be familiar to everyone. Anyone who is familiar with js knows this, but some new users are not very familiar with the usage of the two, the following is a brief introduction.
1. setInterval () usage _ Learning
The Code is as follows:
// Method for Automatic execution every secondVar c = 0;Function showLogin (){Alert (c ++ );}// SetInterval method or string, millisecond, parameter array (method ))SetInterval ("
SetTimeout and setInterval are two amazing methods of window objects. They are used to call a function or code at a scheduled or delayed time. (New users may think that setTimeout and setInterval are javascript Functions, which is incorrect. Beginners can easily confuse javascript Object functions with DOM object methods .)
Let's start with a piece of code. Let's guess what the results will look like in va
1. SetInterval () Use _ Learning
Copy Code code as follows:
Automatic execution every second of a method
var c=0;
function Showlogin ()
{
Alert (c + +);
}
SetInterval method or string, milliseconds, array of arguments (method))
SetInterval ("Showlogin ()", "1000");
2.setTimeout
SetTimeout () method of use in JS class
settimeout
This problem is also in Baidu's front-end technical college encountered in the task needs to use JS to achieve the evaluation of the animation tutor SetInterval will lead to the bug did not understand the following to share their own learning processUnderstand the single thread again always say that JS is a single-threaded, in fact, I do not have a good understanding of the meaning of this single-threaded, such as my understanding of this settimeout (
that the GUI rendering thread and JS engine are mutually exclusive. When the JS engine is executed, the GUI thread will be suspended, gui updates are saved in a queue and executed immediately when the JS engine is idle.
Event trigger thread. When an event is triggered, the thread adds the event to the end of the queue to be processed, waiting for processing by the JS engine. These events can come from the code blocks currently executed by the JavaScript engine, such as
Definition and usage
The setTimeout () method is used to call a function or computing expression after a specified number of milliseconds.Syntax
SetTimeout (code, millisec)
Parameters
Description
Code
Required. The JavaScript code string to be executed after the function to be called.
Millisec
Required. The number of milliseconds to wait before executing th
SetTimeout () is the method of window, but we all skip the top-level Object Name of window. This is used to set a time. When the time is reached, a specified method will be executed.
SetTimeout
Example of setTimeout syntax
Use setTimeout to execute the function
SetTim
The settimeout you don't know about SetInterval () and settimeout () return valuesSetInterval (), SetTimeout () returns a value that is generally considered an ID, passes this ID value to Clearinterval (), and cleartimeout () can cancel execution, for example:
12345678
varintervalTimer=setInterval(function(){console.log(1)},3000);console.log(
SetTimeout() Method is used to call a function or computing expression after a specified number of milliseconds. The following describes how to use setTimeout () in the js class:
SetTimeout (expression, latency)
SetTimeout (expression, interaction time)
The delay time/interaction time is in the unit of luxury seconds (
SetTimeout (expression, delay time); Unit: MS (MS); 1 S = 1000 ms;
Setinterval (expression, interaction time); Unit: MS (MS); 1 S = 1000 ms;
Window. setTimeout ()
During execution, it executes an expression or function from the specified time delay after loading; only once; used with window. cleartimeout.
Window. setinterval ()
During execution, it executes an expression or function at a specified time afte
Http://www.cnblogs.com/Wenwang/archive/2012/01/06/2314283.htmlHttp://www.cnblogs.com/yangjunhua/archive/2012/04/12/2444106.htmlThe following reference: http://evantre.iteye.com/blog/17187771, the origin of the topicWhen I was wandering around, I saw a self-answering question:What are the recommended questions and answers on the front-end development field? , and then what are the classic Web front-end or JavaScript interview pen questions? See the question: What is the difference between the fol
SetTimeout definition and usage: the SetTimeout () method is used to call a function or evaluate an expression after a specified number of milliseconds. Syntax: setTimeout (code,millisec) parameters: code (required): The JavaScript code string to execute after the function to be called. millisec (required): The number of milliseconds to wait before executing t
Understand the setTimeout and setInterval In the javascript timer, and the js timer setinterval.
I. Explanation
1. Overview
SetTimeout: Call a function or execute a code snippet after the specified Delay Time
SetInterval: periodically calls a function or executes a piece of code.
2. Syntax
SetTimeout:
var timeoutID = window.setTimeout(func, delay, [param1, param2
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.