博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JS特训之定时器的使用与清除
阅读量:2065 次
发布时间:2019-04-29

本文共 558 字,大约阅读时间需要 1 分钟。

JS定时器主要有一下两种方法
  • setInterval() :

    按照指定的周期(以毫秒计)来调用函数或计算表达式。方法会不停地调用函数,直到 clearInterval() 被调用或窗口被关闭。

    setInterval(code,millisec,lang)

  • setTimeout() :

    在指定的毫秒数后调用函数或计算表达式。

    setTimeout(code,millisec,lang)

    code 必需。要调用的函数后要执行的 JavaScript 代码串。

    millisec 必需。在执行代码前需等待的毫秒数。
    lang 可选。脚本语言可以是:JScript | VBScript | JavaScript
    —from https://www.runoob.com/w3cnote/js-timer.html

未命名定时器的清除
setInterval(()=>{ console.log(1)},3000)  //示例定时器	//清除	for(let i=0;i<999;i++){		clearInterval(i)	}
已命名定时器清除
let time = setInterval(()=>{ console.log(1)},1000)  //示例定时器	//清除	clearInterval(time)

转载地址:http://skzmf.baihongyu.com/

你可能感兴趣的文章
数据结构 拓扑排序
查看>>
(PAT 1040) Longest Symmetric String (DP-最长回文子串)
查看>>
(PAT 1145) Hashing - Average Search Time (哈希表冲突处理)
查看>>
(1129) Recommendation System 排序
查看>>
PAT1090 Highest Price in Supply Chain 树DFS
查看>>
(PAT 1096) Consecutive Factors (质因子分解)
查看>>
(PAT 1019) General Palindromic Number (进制转换)
查看>>
(PAT 1073) Scientific Notation (字符串模拟题)
查看>>
(PAT 1080) Graduate Admission (排序)
查看>>
Play on Words UVA - 10129 (欧拉路径)
查看>>
mininet+floodlight搭建sdn环境并创建简答topo
查看>>
【UML】《Theach yourself uml in 24hours》——hour2&hour3
查看>>
【linux】nohup和&的作用
查看>>
【UML】《Theach yourself uml in 24hours》——hour4
查看>>
Set、WeakSet、Map以及WeakMap结构基本知识点
查看>>
【NLP学习笔记】(一)Gensim基本使用方法
查看>>
【NLP学习笔记】(二)gensim使用之Topics and Transformations
查看>>
【深度学习】LSTM的架构及公式
查看>>
【深度学习】GRU的结构图及公式
查看>>
【python】re模块常用方法
查看>>