惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
MongoDB | Blog
MongoDB | Blog
The Register - Security
The Register - Security
T
The Blog of Author Tim Ferriss
A
About on SuperTechFans
Vercel News
Vercel News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Jina AI
Jina AI
Stack Overflow Blog
Stack Overflow Blog
Cisco Talos Blog
Cisco Talos Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
W
WeLiveSecurity
S
Securelist
I
Intezer
F
Full Disclosure
WordPress大学
WordPress大学
腾讯CDC
酷 壳 – CoolShell
酷 壳 – CoolShell
Latest news
Latest news
aimingoo的专栏
aimingoo的专栏
C
Cisco Blogs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
The Exploit Database - CXSecurity.com
P
Proofpoint News Feed
K
Kaspersky official blog
阮一峰的网络日志
阮一峰的网络日志
P
Proofpoint News Feed
J
Java Code Geeks
人人都是产品经理
人人都是产品经理
雷峰网
雷峰网
AWS News Blog
AWS News Blog
T
Tenable Blog
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
L
LINUX DO - 最新话题
小众软件
小众软件
T
Threat Research - Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
The GitHub Blog
The GitHub Blog
爱范儿
爱范儿
N
News and Events Feed by Topic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
量子位
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Forbes - Security
Forbes - Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
U
Unit 42
O
OpenAI News
V
V2EX
T
Troy Hunt's Blog

博客园 - 唯一浩哥

2026 年,macbook air 2015 升级硬盘注意事项 Java集合系列-HashSet Java基础系列-单例的7种写法 Java基础系列-Lambda Java基础系列-SPI你认识吗 Java基础系列-时间日期API Java基础系列-RandomAccess Java基础系列-Optional 那些字段适不适合建索引? Mysql笔记 Spring知识点 Java基础系列-浅拷贝和深拷贝 前端-jquery知识点 Java基础系列-substring的原理 - 唯一浩哥 - 博客园 Java设计模式之《抽象工厂模式》及使用场景 - 唯一浩哥 - 博客园 Java基础系列-Enum深入解析 - 唯一浩哥 - 博客园 Java基础系列-Collector和Collectors - 唯一浩哥 - 博客园 Java基础系列-Stream - 唯一浩哥 - 博客园 Java并发编程系列-AbstractQueuedSynchronizer - 唯一浩哥 - 博客园
前端-javascript知识点
唯一浩哥 · 2020-05-28 · via 博客园 - 唯一浩哥

1、计时器

js中有两个计时器函数:

  • setInterval():以指定时间间隔不断的执行指定代码
  • setTimeout():在指定的时间之后执行指定代码

setInterval()

语法:window.setInterval("function", milliseconds);

function表示指定执行的代码
milliseconds表示时间间隔,毫秒级

var timer1 = setInterval(function(){myTimer();}, 1000*10);
function myTimer(){
      // 执行的代码
}

可以使用clearInterval()方法停止执行,前提是需要将timer定义为全局变量

clearInterval(timer1);

setTimeout()

语法:window.setTimeout("function", milliseconds);

function表示指定执行的代码
milliseconds表示指定时限,毫秒级

var timer2 = setTimeout(function(){myTimer();}, 1000*10);
function myTimer(){
      // 执行的代码
}

可以使用clearTimeout()方法停止执行,前提是需要将timer定义为全局变量

clearTimeout(timer2);