JavaScript timer example analysis _ javascript skills

Source: Internet
Author: User
This article mainly introduces the JavaScript timer example analysis. For more information, see 1. what is a JavaScript timer?

In JavaScript, we can execute code after the set interval, rather than immediately after the function is called.

2. timer type

One-time timer: triggered only once after the specified delay time.
Interval trigger timer: triggered at a certain interval.

3. timer method

1): one-time timer

A): setTimeout (): executes the code after the specified delay time.

Syntax: setTimeout (code, latency );

Parameter description:

1. the function to be called or the code string to be executed.
2. latency: The waiting time before code execution, in milliseconds (1 s = 1000 ms ).

B): clearTimeout (): cancels the setTimeout () setting.

Syntax: clearTimeout (timer)

Parameter description:
Timer: the ID value returned by setTimeout. This value identifies the delayed execution code block to be canceled.

Call the setTimeout () and clearTimeout () latency methods:

The code is as follows:






JavaScript 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.