【JS】定时器的开启与关闭
<!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>
本文来自博客园,作者:木子欢儿,转载请注明原文链接:https://www.cnblogs.com/HGNET/p/16462804.html