<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>定时器</title>
</head>
<body>
<button id="closedsq">关闭</button>
<script>

//间隔定时器:按照周期去执行
//延时定时器: 在固定的时间后执行
var time1=setInterval(function () {
    console.log('间隔定时器')
},1000)

var time2=setTimeout(function () {
    console.log('延时定时器')
},1000)
//关闭定时器 不区分定时器种类
// clearInterval()
// clearTimeout()
closedsq.onclick=function () {
    clearInterval(time1)
    clearInterval(time2)
}
</script>
</body>
</html>
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐