In the last development, I encountered the problem of setTimeout parameter passing in IE. in IE, setTimeout does not pass in parameters. For example, the following code does not pass in a in IE, two Parameters of BSetTimeout (function (a, B ){Alert (
1. The SetTimeout () method is used to call a function or evaluate an expression after a specified number of milliseconds;If you need to execute multiple times, you call SetTimeout () again;Example: an infinite loop with a stop
Whether it is window. setTimeout or window. setInterval, parameters cannot be included when the function name is used as the call handle. If you want to pass in parameters, custom parameters, or event parameters, the solution is to encapsulate them
Reprinted: http://flex4jiaocheng.com/blog/325
You should be familiar with the setTimeout method, and the setinterval method is usually used less frequently. In fact, both of them are very useful "timers", the difference is as follows:
SetTimeout
Recently I encountered a javascript question. The content is as follows:
Try to implement Javascript in the annotation SectionCode, You can add moreCode (if it cannot be implemented, describe the reason why it cannot be implemented ):
VaR OBJ =
Let's take a look at my previous
Article : The Nine traps and comments of JavaScript, which were mentioned in focus poocus. The original author's understanding of this is biased, not just the issue of IE, but the issue of thread implementation by
If window. setTimeout is frequently used on the page, the Code judgment may be confusing.
For example
If (! Timerid)
Timerid = Window. setTimeout (dosomething, duration );
Window. cleartimeout (timerid );
And so on.
Methodqueue is an object used to
The common usage of setTimeout is as follows:
var arr = [1,9,2,8,3,7,4,6,4,5];for(var i = 0, len = arr.length; i setTimeout(function(x){ console.log(x); },arr[i],arr[i]); }
Although this is not a good usage, the
See the followingCode:
VaR STR = 'aaa'; var num = 2; function auto (Num) {alert (Num);} setTimeout ('Auto (Num) ', 4000 );
In this way, the write operation works normally, but if it is said that this is a parameter transfer, it is better to
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
Both functions are timers, which are functions of the Window object, but there are many differences.1. Fundamental differencesSetTimeout ("function", time), function name or code, time unit millisecond, refers to the delay of a specified period
showMe is not defined error with SetTimeout ("ShowMe ()", 1000). This is because the SHOWME () function is not in the setTimeout call environment. Reproduced in this article explains and solves this problem. The original title is: 2.3. Coding your
Read the JavaScript Advanced Programming (third Edition) today, and found that settimeout is better than setinterval, and feels that it does. Usually use setinterval more points, now or turn the idea. I learned it again. The notes are as follows:----
1,setinterval ()The SetInterval () method can invoke a function or expression according to a specified period, and he will keep calling the function until the call to the Clearinterval () method or window is closed. The ID value returned by
Several examples illustrate how to run setTimeout in JS.
Example: 1
Function test () {var a = 1; setTimeout (function () {alert (a); a = 5 ;}, 1000) ;}test (); alert (0 ); // The first two settimeouts are delayed. Therefore, execute thisResult: 0
When using JScript, we sometimes need to execute a method at intervals, for example, to generate webpage UI animation effects. This is often the setInterval or setTimeout method, but since these two methods are the Timer threads simulated by the
Application Examples of the js setTimeout Function
The window. setTimeout method is used to delay the execution of a function (method. However, it is defective when calling the specified method and passing parameters.
Infinite Loop
The
SetTimeout are often used to delay the running of a function, using the method ofSetTimeout (function () {...}, timeout);Sometimes settimeout (function...,0) is used for asynchronous processing, for examplefunction f () {...//Get readySetTimeout
In fact, settimeout and setinterval have the same syntax. They all have two parameters, one is the code string that will be executed, and one is the time interval in milliseconds, and the code will be executed after that time period. But there's a
The difference is that setinterval executes the code once every other specified time period, with repeatability. and settimeout only executes once after the call.
The following is a deep understanding of two functions through the establishment of
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.