Javascript jQuery倒计时-重置计时器

Javascript jQuery倒计时-重置计时器,javascript,jquery,timer,countdown,Javascript,Jquery,Timer,Countdown,我正在使用插件,有一个快速查询 我的代码当前如下所示: function doCountdown(){ var nextNoon = new Date(); if (nextNoon.getHours()>=12){ nextNoon.setDate(nextNoon.getDate()+1); } nextNoon.setHours(11,30,0,0); $('h3 .timer strong').countdown({until: nextNoon,

我正在使用插件,有一个快速查询

我的代码当前如下所示:

function doCountdown(){
    var nextNoon = new Date();
    if (nextNoon.getHours()>=12){ nextNoon.setDate(nextNoon.getDate()+1); }
    nextNoon.setHours(11,30,0,0);

    $('h3 .timer strong').countdown({until: nextNoon, compact: true, 
        description: '',  onExpiry: function(){doCountdown()}});
}

$(window).load(function(){
     doCountdown();
});
所以基本上,它会倒计时到下一个
11:30AM
。但是,我需要它在到达
11:30AM
时重置计数器,这样它会自动转到计时器上的
23:59:59

目前,它只是停留在
00:00:00
,即使
doCountdown
函数被调用
onExpiry
(使用
console.log测试,它肯定会调用它)


这是因为javascript基于页面加载时间,然后存储它吗?

原因是您的
nextNoon
创建错误计算了上午11:30到下午12:00之间的时间。对于这半个小时的时间段,
if()
将计算为false,因此它将时间设置为当天上午11:30。但是我们已经度过了这段时间,因为我们在上午11:30到中午12点之间。所以倒计时将变为零

您需要执行以下操作:

var todaysNoon = new Date(), nextNoon = new Date();
todaysNoon.setHours(11,30,0,0);
if (todaysNoon <= nextNoon){ nextNoon.setDate(nextNoon.getDate()+1); }
nextNoon.setHours(11,30,0,0);
var todaysNoon=new Date(),nextNoon=new Date();
今日凌晨11,30,0,0,;
如果(今天)