How to delete delayer in JavaScript

青灯夜游
Release: 2021-10-27 18:24:26
Original
4588 people have browsed it

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)
Copy after login

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

Example:

       
Copy after login

clearTimeout()

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

Syntax:

clearTimeout(id)
Copy after login

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

Example:

   
Copy after login

[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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!