JavaScript timer details and instance _ javascript skills

Source: Internet
Author: User
This article details the JavaScript timer and examples. If you need it, you can refer to setting the latency in JS:
SetInterval is similar to setTimeout. SetTimeout is used to perform an operation after a delay period.
SetTimeout ("function", time) sets a timeout object
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
Use a timer to implement deferred or repeated JavaScript Execution
The window object provides two methods to implement the timer effect, namely window. setTimeout () and window. setInterval. The former allows a piece of code to run after a specified time, while the latter allows a piece of code to run once every time. Their prototype is as follows:
Window. setTimeout (expression, milliseconds );
Window. setInterval (expression, milliseconds );
Expression can be a piece of code enclosed in quotation marks or a function name. at the specified time, the system automatically calls the function, when a function name is used as the call handle, it cannot contain any parameters. When a string is used, you can write the parameters to be passed. The second parameter of the two methods is milliseconds, which indicates the number of milliseconds of delay or repeated execution. The following describes two methods.
1. window. setTimeout Method
This method can delay the execution of a function, for example:

The Code is as follows:


Related Article

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.