0
点赞
收藏
分享

微信扫一扫

css html js 定时器

全栈顾问 2023-02-01 阅读 66


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>

</style>
</head>
<body>
<button id="stop">停止</button>
</body>
</html>
<script>
function a(){
console.log('ok')
}
var taskId = setInterval(a,1000);

var taskId2 = setInterval(function(){
console.log('ok2')
},1000);
var stop = document.getElementById('stop');
stop.onclick = function(){
//停止定时器的进程
clearInterval(taskId)
clearInterval(taskId2)
}
</script>


举报

相关推荐

0 条评论