<!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>
</head>
<body>
<input type="button" value="点击生成随机数" id="btn">
<script>
btn = document.getElementById("btn");
lock = false;
btn.onclick = function(){
if(lock == true){
return;
}
else{
console.log(Math.random());
lock = true;
window.setTimeout(function(){
lock = false;
},2000);
}
}
</script>
</body>
</html>
延时器 - 函数节流
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:定时器 - 简单运动
下一篇:完整轮播图案例
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
SpringBoot使用Redis实现延时队列
SpringBoot使用Redis实现延时队列
延时队列 Redis SpringBoot -
如何通过Redis实现延时任务?
如何通过Redis实现延时任务? 先说结论,有两种方式可以实现: 通过Redis监听过期key实现。 使用Redisson 内置的延时队列实现。
Redis 消息队列 延迟任务 定时任务 Redisson