function ShowTime() {
var now = new Date();
var hrs = 19-now.getHours();
var mins = 60-now.getMinutes();
var secs = 60-now.getSeconds();
timeLeft = " " +hrs+' '+mins+' '+secs+' ';
$("#countdown").html(timeLeft);
}
var countdown;
function StopTime() {
clearInterval(countdown);
}
setInterval(ShowTime ,1000);晚上8:30在这里。我想如果他得到9点,倒计时重新启动,它每晚上9点重新启动。结果是阴性..。
发布于 2016-01-21 12:46:57
function ShowTime() {
var now = new Date();
var hrs;
var currentHours = now.getHours();
if(currentHours>19){
hrs = 24-currentHours+19;
}else{
hrs = 19-now.getHours();
}
var mins = 60-now.getMinutes();
var secs = 60-now.getSeconds();
timeLeft = " " +hrs+' '+mins+' '+secs+' ';
$("#countdown").html(timeLeft);
}发布于 2016-01-21 12:32:46
如果要使用countdown,则应赋值clearInterval
countdown = setInterval(ShowTime ,1000);发布于 2016-01-21 12:36:05
请把逻辑弄成这样。
If now >19 then
timeLeft is (24-now)+19
else hrs = 19-now;https://stackoverflow.com/questions/34923795
复制相似问题