Home>Article>Web Front-end> How to delete delayer in JavaScript

How to delete delayer in JavaScript

青灯夜游
青灯夜游 Original
2021-10-27 18:24:26 4590browse

How to delete a delayer in JavaScript: 1. Use the "clearInterval(id)" statement to delete the delayer defined by setInterval(); 2. Use the "clearTimeout(id)" statement to delete it Delay defined by setTimeout().

How to delete delayer in JavaScript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

JavaScript delayer, also known as timer, sometimes also called "timer", is used to perform certain tasks after a specified time, similar to the alarm clock in our lives.

In JavaScript, we can use delayers to delay the execution of certain codes, or to repeatedly execute certain codes at fixed intervals.

JavaScript provides two ways to set the timer, namely setTimeout() and setInterval(); and there are two corresponding ways to delete the delayer:

  • clearInterval() Cancel the timeout set by setInterval().

  • clearTimeout() Cancel the timeout set by the setTimeout() method.

clearInterval()

clearInterval() method can cancel the timeout set by setInterval().

Syntax:

clearInterval(id)

The parameter of the clearInterval() method must be the ID value returned by setInterval().

Example:

       

clearTimeout()

The clearTimeout() method can cancel the timeout set by the setTimeout() method.

Syntax:

clearTimeout(id)

The parameter of the clearInterval() method must be the ID value returned by setTimeout().

Example:

   

[Recommended learning:javascript advanced tutorial]

The above is the detailed content of How to delete delayer in JavaScript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn