Web page effects settimeout and SetInterval Execute command function method periodically
settimeout (expression, delay time)At execution time, after the specified time is delayed, the expression is executed once, remembering that the number is once
Automatic changes with settimeout to display the effect of random numbers:
Window.settimeout ("Softphoneui.
SetInterval () Definition and usage
The SetInterval () method executes a function or expression in the specified period (in milliseconds). The method loops through the function until the function is explicitly stopped by using clearinterval (), or the window is closed. The parameter of the Clearinterval () function is the ID value returned by SetInterval ().
Grammar
SetInterval (code,millisec[, "Lang"])
Code required. The function to invoke or the code string to execute.
Millisec must. The
The settimeout and setinterval functions that JavaScript uses to handle delay and timed tasks are widely used to handle time-lapse and timed tasks, such as opening a Web page for a period, popping up a login box, sending asynchronous requests to get the latest data at regular intervals, and so on. But there are differences in their application.The SetTimeout () method is used to call a function or evaluate
Today in writing a picture switching problem has animation lag problem, only to check settimeout and cleartimeout. The previously written picture player also has a similar problem with the Auto Start button and the Stop button,Others are normal, the problem is that each time you click the Start button many times, the speed of the picture will be changed a lot, and there is no regularity. I didn't think about it at the time, until today I had a similar
The fourth edition of the JavaScript authoritative guide says "Window object method settimeout () is used to schedule a JavaScript snippet to run at a specified time in the future."SetTimeout (Foo,i); Foo is the callback function, I is the delay timeNote that the word "future", SetTime will put the Foo function in the queue, when the thread is idle, JavaScript will execute the event in the queue.Look at the
SetTimeout is often used in JavaScript to delay the execution of a function, for example:
SetTimeout (function () {alert ( quot; Hello World quot;) ;}, 1000)
The alert window will pop up one second after this sentence is executed. Let's look at this section again:
Function (){
SetTimeout (function () {alert (1)}, 0 );
Alert (2 );
}
A ();
Note that the
The code is as follows
Copy Code
ShowTime ();function ShowTime (){var today = new Date ();Alert ("The time is:" + today.tostring ());SetTimeout ("ShowTime ()", 5000);}
Once this function is called, the time is displayed every 5 seconds.
The code is as follows
Copy Code
settimeout (function () {Alert (' Hello! ');}, 0);SetInterval (callbackfunction, 10
How to pass parameters to SetTimeout, setintervallook at the following code:
var str = ' AAA ';
var num = 2;
function Auto (num) {
alert (num);
}
SetTimeout (' Auto (num) ', 4000);
This is a good way to write, but as it says this is a parameter pass, it's more of a global variable that is used directly. Therefore, this writing is not necessary, in general, more is used to pass local v
JavaScript's settimeout and setinterval functions are widely used to deal with delays and timed tasks, such as opening a Web page for a period of time after a pop-up login box, the page to send asynchronous requests every time to obtain the latest data and so on. But there are differences in their application.
The settimeout () method is used to call a function or evaluate an expression after a specified n
SetTimeout Method
Evaluates an expression after a specified number of milliseconds have elapsed. Syntax var retval = window.settimeout (expression, msec, language); Parameters expression [in]
Type: Variant
Variant that specifies the function pointer or a string that indicates the code is executed when the specified I Nterval has elapsed. msec [in]
Type: Integer
The Integer that specifies the number of milliseconds. language [in, optional]
Type: Varian
If you call other methods directly in ready, an error indicating that the object is missing is prompted. The solution is as follows:
Method 1. Apply jquery extension to solve this problem.
$ (Document). Ready (function (){
$. Extend ({Show: function (){Alert ("ready ");}});Setinterval ("show ()", 3000 );});
Method 2: Do not use quotation marks or parentheses when specifying the function to be executed regularly.
$ (Function (){Function show (){Alert ("ready ");}Setinterval (
The setTimeout method is a Timer Program, that is, after what time. After the job is finished, pull it down.The setInterval method indicates that an operation is executed repeatedly at a certain interval.If you use setTimeout to implement the setInerval function, you need to regularly call yourself in the executed program. To clear a counter, you need to call different clearing methods based on the method u
Method 1. Apply jQuery extension to solve this problem.
Copy codeThe Code is as follows: $ (document). ready (function (){
$. Extend ({
Show: function (){
Alert ("ready ");
}
});
SetInterval ("show ()", 3000 );
});
Method 2: Do not use quotation marks or parentheses when specifying the function to be executed regularly.
Copy codeThe Code is as follows: $ (function (){
Function show (){
Alert ("ready ");
}
SetInterval (show, 3000); // note that the function name is not enclosed in quotation mar
the difference between settimeout and setinterval methodSetTimeout () is used to set the corresponding function or code to execute after the specified time., executed at the global scope SetTimeout (Code,time[,args ...]) code: function or JS code to be executed, time to wait, args: parametersuch as: function SayHello (name, age) { //popup message after 5 Seconds "My name Codeplayer, 18 years old this year!"
Contents of this section: SetInterval and SetTimeoutOne, SetInterval () define and use the SetInterval () method to execute a function or expression according to the specified period (in milliseconds). The method keeps looping through the function until the function is explicitly stopped using clearinterval () or the window is closed. The parameter of the Clearinterval () function is the ID value returned by SetInterval (). Syntax SetInterval (code,millisec[, "Lang"]) code required. The function
scenario.MethodIn fact, settimeout and setinterval have the same syntax. They all have two parameters, one is the code string to execute, and one is the time interval in milliseconds, and the code executes after that time period.However, the two functions are still different, setinterval after the execution of the code, after the fixed time interval, it will also automatically repeat the code, and settimeout
scenario.MethodIn fact, settimeout and setinterval have the same syntax. They all have two parameters, one is the code string to execute, and one is the time interval in milliseconds, and the code executes after that time period.However, the two functions are still different, setinterval after the execution of the code, after the fixed time interval, it will also automatically repeat the code, and settimeout
SetTimeout and setInterval in jsSetTimeout and setInterval
Javascript is run in the javascript engine of the browser in a single thread mode,The functions of setTimeout and setInterval are to insert the code you want to execute into a code queue maintained by the js engine at a specified time point.
The following methods are used for window objects:SetTimeout () and clearTimeout ()SetInterval () and clearIn
Method 1. Apply jQuery extension to solve this problem. Copy codeThe Code is as follows:$ (Document). ready (function (){$. Extend ({Show: function (){Alert ("ready ");}});SetInterval ("show ()", 3000 );});Method 2: Do not use quotation marks or parentheses when specifying the function to be executed regularly. Copy codeThe Code is as follows:$ (Function (){Function show (){Alert ("ready ");}SetInterval (show, 3000); // note that the function name is not enclosed in quotation marks or arc!// Whe
The setTimeout method is a Timer Program, that is, after what time. After the job is finished, pull it down.The setInterval method indicates that an operation is executed repeatedly at a certain interval.If you use setTimeout to implement the setInerval function, you need to regularly call yourself in the executed program. To clear a counter, you need to call different clearing methods based on the method u
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.