定时器 js 点击按钮开启倒计时,怎么防止连续点击按钮,倒计时不受影响 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 setInterval轻松搞定if (this.Querytime == 0) { this.Querytime = 10; const timer = setInterval(() => { if (!this.Querytime) { clearInterval(timer); } else { this.Querytime = this.Querytime - 1; } }, 1000); } else { this.$info(`操作太快啦,请${this.Querytime}秒~~`); return; } let setTime = nullexe()function exe(){ if(setTime){clearTimeout(setTime)} setTime = setTimeout(function(){ console.log("=======") //你的代码 })}// 不建议弹出什么点击太频繁之类的提示框, 用户体验太差 这个问题的焦点在点击按钮防止连续点击,不在于倒计时,所以我直接使用setTimeout来防止连续点击,而倒计时代码我就不参合了,毕竟楼上这么多setInterval 第一次点击后,将点击按钮设置为不可用 disabled=true var 一个变量,赋值为false,计时开始时为true,判断下这个变量就可以了。 <body> <button onclick="btn()">click</button> <span id="span1">10</span> <script> let span1 = document.getElementById("span1"); let isClick = false; function btn () { let count = 10; if (isClick == false) { isClick = true; let time = setInterval(function (){ count-- span1.innerHTML = count if (count <= 0) { clearInterval(time) span1.innerHTML = "点击重新开始" isClick = false } }, 1000) } } </script></body> jquery中trigger传json的话,会解析错误,有办法处理吗 js 下载文件的问题! jquery 怎么做渐入渐出效果???!!! 请问我想更改li元素鼠标经过是的类名,这个怎么又问题,谢谢,刚学 如何按指定获取数组中的值 图片上使用attachEvent的问题 一个图片提交的问题(在线等) 有点难度问题,高手请进 超级简单的问题,单是我不会 :( 虚心求教。顶者有分! 在netscape中openDialog为什么不起作用 html5 js 播放webrtc rtsp视频流 解读一段js生成签名的代码逻辑,实现看不懂,求教!
this.Querytime = 10;
const timer = setInterval(() => {
if (!this.Querytime) {
clearInterval(timer);
} else {
this.Querytime = this.Querytime - 1;
}
}, 1000);
} else {
this.$info(`操作太快啦,请${this.Querytime}秒~~`);
return;
}
let setTime = null
exe()
function exe(){
if(setTime){clearTimeout(setTime)}
setTime = setTimeout(function(){
console.log("=======")
//你的代码
})
}
// 不建议弹出什么点击太频繁之类的提示框, 用户体验太差
所以我直接使用setTimeout来防止连续点击,而倒计时代码我就不参合了,
毕竟楼上这么多setInterval
<button onclick="btn()">click</button>
<span id="span1">10</span>
<script>
let span1 = document.getElementById("span1");
let isClick = false;
function btn () {
let count = 10;
if (isClick == false) {
isClick = true;
let time = setInterval(function (){
count--
span1.innerHTML = count
if (count <= 0) {
clearInterval(time)
span1.innerHTML = "点击重新开始"
isClick = false
} }, 1000)
}
}
</script>
</body>