当前位置:网站首页>type of timer
type of timer
2022-07-31 15:22:00 【I must win this time】
One. Timer setTimeout, setInterval
(1) setTimeout
setTimeout(() => {console.log('It's time to execute me');}, timeout);This timer will only run once
Code:
setTimeout(() => {console.log('It's time to execute me');}, 2000);
You can see the content inside after 2s hit.
Please continue reading
(2) setInterval
setInterval(() => {console.log('It's time to execute me');}, interval);Code:
setInterval(() => {console.log('It's time to execute me');}, 2000);
It will be executed every 2s.
2. Clear timer clearTimeout
(1) clearTimeout(timer name)
let timer = setTimeout(() => {console.log('It's time to execute me');}, 2000);clearTimeout(timer)As you can see, nothing is printed in the console.
(2)clearInterval(timer name)
let timer1 = setInterval(() => {console.log('It's time to execute me');}, 2000);setTimeout(() => {clearInterval(timer1)}, 6000);
What you can see is that it is executed three times, it is no longer executed, and it has been cleared at this time.
To clear a timer, first give it a name.and finally clear it.
边栏推荐
- 基于极限学习机(ELM)进行多变量用电量预测(Matlab代码实现)
- 「秋招系列」MySQL面试核心25问(附答案)
- abaqus find contact pairs报错:surface name is already in use
- DBeaver连接MySQL 8.x时Public Key Retrieval is not allowed 错误解决
- Insert into data table to insert data
- 435. 无重叠区间
- ASP.NET Core generates continuous Guid
- 学习笔记12--路径-速度分解法之局部路径搜索
- 乡村基冲刺港交所:5个月期内亏2224万 SIG与红杉中国是股东
- Tencent Cloud Deployment----DevOps
猜你喜欢
随机推荐
R language ggplot2 visualization: use the ggmapplot function of the ggpubr package to visualize the MA plot (MA-plot), the font.legend parameter and the font.main parameter to set the title and legend
使用 Chainlink Keepers 实现智能合约函数的自动化执行
Internet banking stolen?This article tells you how to use online banking safely
删除表格数据或清空表格
TextBlock控件入门基础工具使用用法,取上法入门
01 Encounter typescript, build environment
The principle of hough transform detection of straight lines (opencv hough straight line detection)
How useful is four-quadrant time management?
Selenium自动化中无头浏览器的应用
SQL、HQL、JPQL 到底有什么区别
使用 PyTorch 检测眼部疾病
MySQL的相关问题
mongo进入报错
Female service community product design
Why don't you make a confession during the graduation season?
定时器的类型
Deployment应用生命周期与Pod健康检查
The use of button controls
【CUDA学习笔记】初识CUDA
使用 GraphiQL 可视化 GraphQL 架构









