小编向大家介绍过js定时器的启动方法setTimeout与setInterval,既然会启动定时器,那也有关停定时器,清除定时效果的必要。本文介绍js定时器清除方法:clearTimeout() 和clearInterval() 。
方法一:clearTimeout(timeId)
取消由 setTimeout() 方法设置的 timeId。
1、语法
1 |
|
2、参数
要取消的延迟执行代码块。
3、使用实例
1 2 3 4 5 6 7 8 9 10 11 12 |
|
方法二:clearInterval(timeId)
取消由 setInterval() 设置的 timeId。
1、语法
1 |
|
2、参数
清除的定时器对象
3、使用实例
1 2 3 4 5 6 7 8 9 10 11 12 |
|
以上就是js定时器清除方法clearTimeout() 和clearInterval() 的原理及实现实例,希望能对你有帮助哦~