js--Timer

Source: Internet
Author: User

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:

    1. 
          

js--Timer

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.