我有以下脚本。这显示了DIV的倒计时。这一切都很好。但是,如果计数器为0(表示;没有天/小时/分钟/秒),页面必须自动刷新一次。我好几天都在寻找解决方案但却无法找到解决方案。谁可以帮我这个?
$(function(){
var note = $('#note'),
ts = new Date(2010),
newYear = false;
if((new Date()) > ts){
// The new year is here! Count towards something else.
// Notice the *1000 at the end - time must be in milliseconds
ts = (new Date('<?php echo $newDateUserTimerDate; ?>')).getTime() + 1*1*1*<?php echo $minutes; ?>*1000;
newYear = false;
//$start_date = new DateTime('2017-04-21 04:10:58');
}
$('#countdown').countdown({
timestamp : ts,
callback : function(days, hours, minutes, seconds){
var message = "";
message += days + " day" + ( days==1 ? '':'s' ) + ", ";
message += hours + " hour" + ( hours==1 ? '':'s' ) + ", ";
message += minutes + " minute" + ( minutes==1 ? '':'s' ) + " and ";
message += seconds + " second" + ( seconds==1 ? '':'s' ) + " <br />";
if(newYear){
//message += "left until the new year!";
}
else {
//message += "left to 10 days from now!";
}
note.html(message);
}
});
});
答案 0 :(得分:0)
解决方案:
location.reload();
例如:
$(function(){
var note = $('#note'),
ts = new Date(2010),
newYear = false;
if((new Date()) > ts){
// The new year is here! Count towards something else.
// Notice the *1000 at the end - time must be in milliseconds
ts = (new Date('<?php echo $newDateUserTimerDate; ?>')).getTime() + 1*1*1*<?php echo $minutes; ?>*1000;
newYear = false;
//$start_date = new DateTime('2017-04-21 04:10:58');
}
$('#countdown').countdown({
timestamp : ts,
callback : function(days, hours, minutes, seconds){
var message = "";
message += days + " day" + ( days==1 ? '':'s' ) + ", ";
message += hours + " hour" + ( hours==1 ? '':'s' ) + ", ";
message += minutes + " minute" + ( minutes==1 ? '':'s' ) + " and ";
message += seconds + " second" + ( seconds==1 ? '':'s' ) + " <br />";
if(newYear){
//message += "left until the new year!";
location.reload();
}
else {
//message += "left to 10 days from now!";
}
note.html(message);
}
});
来源: