当id dlbtn
上触发click事件时,这是我的jquery倒计时代码var settimmer = 0;
$(function() {
$('#dlbtn').click(function() {
$('#dlnotify').toggle('slow');
window.setInterval(function() {
var timeCounter = $("b[id=show-time]").html();
var updateTime = eval(timeCounter) - eval(1);
$("b[id=show-time]").html(updateTime);
if (updateTime <= 0) {
window.location = ('/dl.php?fid=12');
$('#dlnotify').hide();
}
}, 500);
updateTime--;
return false; //Kill the Event after request
});
});
我的脚本继续点击dl.ph页面
答案 0 :(得分:0)
我不是100%确定问题是什么,但要删除setInterval
您需要拨打clearInterval
http://www.w3schools.com/jsref/met_win_setinterval.asp
试试这段代码:
var settimmer = 0;
$(function() {
$('#dlbtn').click(function() {
$('#dlnotify').toggle('slow');
settimmer =window.setInterval(function() {
var timeCounter = $("b[id=show-time]").html();
var updateTime = eval(timeCounter) - eval(1);
$("b[id=show-time]").html(updateTime);
if (updateTime <= 0) {
window.location = ('/dl.php?fid=12');
clearInterval(settimmer); // clear the interval to avoid multiple redirects
$('#dlnotify').hide();
}
}, 500);
updateTime--;
return false; //Kill the Event after request
});
});