In JAVASCRITP, there are two dedicated functions for timers, respectively:
1. Countdown Timer: Timename=settimeout ("function ();", delaytime);
2. Cycle Timer: Timename=setinterval ("function ();", delaytime);
The first parameter, "function ()", is the action to be performed when the timer is triggered, either as a function or as a function, separated by a ";" between functions.
For example, to eject two warning windows, you can "function ();" Change to "alert (' First warning window! '); Alert (' Second warning window! '); " ;
The second parameter, "Delaytime", is the time interval, in milliseconds, that is, "5000", which represents 5 seconds.
The countdown timer is the trigger event when the specified time arrives, and the loop timer is the recurring event that occurs when the interval arrives
The difference between the two is that the former only works once, while the latter keeps on acting.
For example, when you open a page and want to automatically jump to another page in a few seconds, you need to use the SetTimeout timer "(" function (), ", Delaytime)", and if you want to set a sentence to a single word, you need to use the loop timer " SetInterval ("function ();", Delaytime) ". Gets the focus of the form, using the document.activeElement.id. Use if to determine if document.activeElement.id and form IDs are the same. For example: if ("mid" = = Document.activeElement.id) {alert ()}, "Mid" is the ID of the form.
Timer:
Used to specify that a program executes after a specific period of time.
JS in the timing of execution, settimeout and setinterval differences, and L lifting method
SetTimeout (Expression,delaytime), after Delaytime, will perform a expression,settimeout application for a period of delay before performing an operation. SetTimeout ("function", time) sets a timeout object
SetInterval (Expression,delaytime), each delaytime, will execute expression. It is often used to refresh an expression. SetInterval ("function", time) sets a timeout object
SetInterval for automatic repetition, settimeout does not repeat.
Cleartimeout (object) clears the set SetTimeout object Clearinterval (object) clears the SetInterval object that has been set
The following are the formats for the two types of functions:
-
-
js--Timer