JS Timer Instance _javascript skill

Source: Internet
Author: User
Tags setinterval time interval

respectively:
1. Inverted 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, it can be a function, or it can be several functions, separated by ";" between functions. For example, to eject two warning windows, you can "function ()". Into
"Alert (' First warning window! '); Alert (' Second warning window! '); , and the second parameter "Delaytime" is the time of the interval, in milliseconds, that is, fill in "5000", which means 5 seconds.
The countdown timer is to trigger an event at a specified time, and the loop timer is a recurring event when the time interval arrives, the difference being that the former is only a function once and the latter is constantly acting.
For example, when you open a page, want to interval a few seconds to automatically jump to another page, you need to use the inverted timer "settimeout (" function (); ", Delaytime)", and if you want to set a sentence into a word of the appearance,
You need to use the loop timer "setinterval" ("function ();", Delaytime).

Gets the focus of the form, the document.activeElement.id is used. Use if to determine whether the ID of the document.activeElement.id and form is the same.
For example: if ("mid" = document.activeElement.id) {alert ();}, "Mid" is the corresponding ID of the form.

Timer:
Used to specify a program to be executed after a certain period of time.

JS in timed execution, settimeout and setinterval differences, and L lifting method

SetTimeout (Expression,delaytime), after Delaytime, will perform a expression,settimeout application after a period of delay, and then do some action.
SetTimeout ("function", time) sets a timeout object

SetInterval (Expression,delaytime), each delaytime, will perform expression. Can often be used to refresh an expression.
SetInterval ("function", time) sets a timeout object

SetInterval for automatic repetition, settimeout will not repeat.

Cleartimeout (object) clears the SetTimeout object that has been set
Clearinterval (object) clears the SetInterval object that has been set

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.