JS timer instance detail analysis _ javascript tips-js tutorial

Source: Internet
Author: User
There are two dedicated timer functions in javascrui. The following describes the two timers. If you need them, refer to 1. countdown timer: timename = setTimeout ("function ();", delaytime );
2. Cyclic Timer: timename = setInterval ("function ();", delaytime );
The first parameter "function ()" is the action to be executed when the timer is triggered. It can be a function or several functions, separated. For example, to bring up two warning windows, you can replace "function ();"
"Alert ('first warning window! '); Alert ('second warning window! '); ", While the second parameter" delaytime "is the interval. in milliseconds, enter" 5000 ", which indicates 5 seconds.
The countdown timer triggers events after the specified time arrives, while the cyclic timer triggers events repeatedly when the time interval arrives. The difference between the two is that the former only works once, the latter does not stop working.
For example, if you want to automatically jump to another page several seconds after opening a page, you need to use the countdown timer "setTimeout (" function (); ", delaytime )", if you want to set a sentence to appear one by one,
You need to use the cyclic timer "setInterval (" function (); ", delaytime )".

To obtain the focus of a form, document. activeElement. id is used. Use if to determine whether the document. activeElement. id and Form ID are the same.
For example, if ("mid" = document. activeElement. id) {alert () ;}, "mid" is the ID of the form.

Timer:
It is used to execute a program after a specific period of time.

Regular execution in JS, difference between setTimeout and setInterval, and l release method

SetTimeout (Expression, DelayTime): After DelayTime, an Expression is executed. setTimeout is used for a delay period before a certain operation.
SetTimeout ("function", time) sets a timeout object

SetInterval (expression, delayTime). Expression is executed for each DelayTime. It is often used to refresh an expression.
SetInterval ("function", time) sets a timeout object

SetInterval indicates automatic repetition, and setTimeout does not.

ClearTimeout (object) clears the set setTimeout object
ClearInterval (object) clears the set setInterval object

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.