JS timer example analysis

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

In javascritp, there are two special function on the timer.


The 1 countdown timer: timename=setTimeout("function();",delaytime);

2 cycle timer: timename=setInterval("function();",delaytime);

The first parameter to “ function (”) is the timer triggers an action to perform, can be a function, can also be a few functions, function using “ ” should be separated. For example, two warning window pops up, will be “ (function); ” change

“alert('The first warning window! '); alert ("second warning window!'); ”; and the second parameter “ delaytime” is the interval of time, in milliseconds, fill in “ 5000”, said 5 seconds.

  Countdown timer is triggered events arrive after a specified time, and the cycle timer is in the interval time of repeated trigger events, the difference is: the former is just a single, while the latter does not stop function.

For example, you open a page, want to an interval of several seconds automatically jump to another page, you will need to use the countdown timer “ setTimeout ("function (&rdquo, delaytime);");, but if you want to be a word is a word,

You need to use a cycle timer“setInterval("function();",delaytime)” .

Focus to obtain the form, is used in document.activeElement.id. To determine the document.activeElement.id and ID are the same with if form.

For example: if ("mid" = = document.activeElement.id) {alert ("mid");}, is to form the corresponding ID.


For specifying the execution of a program in a certain period of time.

Timing is implemented in JS, the difference between setTimeout and setInterval, and l releasing method

setTimeout(Expression,DelayTime),Following the DelayTime, will be the implementation of a Expression, the use of setTimeout on the delayed for some time, then an operation.

setTimeout("function",time) Set a timeout object

setInterval(expression,delayTime),Each DelayTime, will perform the Expression. can often be used to refresh expressions.

setInterval("function",time) Set a timeout object

SetInterval automatic repeat, setTimeout will not repeat.

ClearTimeout (object) clearance has set setTimeout object

ClearInterval (object) clearance has set setInterval object

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Spike at November 17, 2013 - 5:31 PM