IE 中的 jQuery 倒计时功能
我在使用 IE8 及以下版本时遇到了一个奇怪的问题,我的倒计时只应该触发一次,但它一直持续触发,这在现代浏览器中不会发生。有什么办法可以解决这个问题吗?谢谢!目标是在选择输入后开始倒计时。
代码:
$("input").focus (function counter() {
$("input").unbind('focus', counter);
var count = 60;
countdown = setInterval(function(){
$(".clock p").html(count);
if (count == 0) {
$(".while-ticking").fadeOut(1000);
$(".countdown-finished").fadeIn(1000);
}
else {
count--;
}
}, 1000);
});
I'm having a strange issue with IE8 and below where my countdown that's only supposed to fire once keeps fireing, something that doesn't happen in modern browsers. Is there any way to fix this? Thanks! The goal is to have a countdown start once an input is selected.
Code:
$("input").focus (function counter() {
$("input").unbind('focus', counter);
var count = 60;
countdown = setInterval(function(){
$(".clock p").html(count);
if (count == 0) {
$(".while-ticking").fadeOut(1000);
$(".countdown-finished").fadeIn(1000);
}
else {
count--;
}
}, 1000);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样:
编辑:
您需要创建一个倒计时循环。所以我基本上做的是从 60 等待一秒开始并再次调用该函数,然后使用 59.. 等等。当它为 0 时,它不再调用该函数,因此它停止
编辑:
我已经测试了以下内容并且它有效:)倒计时非常好
Try it this way:
Edit:
You need to create a loop for the counting down. So what i basicly do is starting with 60 wait a sec and recall the function again but then with 59.. etc. etc. when its 0 it doesnt call the function anymore so it stopt
Edit:
I have test it the following and it worked :) counting down very well