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().
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!