需要重置自身的Jquery计数器
您好,我在这里添加了代码: 我需要计时器在达到时间0时重新启动,以便在24小时后再次启动-倒计时 你能帮我找到正确的密码吗?那个背景 现在,当它到达时间0时,它以-1,-2等开始 代码如下:需要重置自身的Jquery计数器,jquery,countdowntimer,Jquery,Countdowntimer,您好,我在这里添加了代码: 我需要计时器在达到时间0时重新启动,以便在24小时后再次启动-倒计时 你能帮我找到正确的密码吗?那个背景 现在,当它到达时间0时,它以-1,-2等开始 代码如下: <div id="countdown"></div> function ShowTime() { var now = new Date(); var hrs = 18-now.getHours(); var mins = 60-now.getMinutes();
<div id="countdown"></div>
function ShowTime() {
var now = new Date();
var hrs = 18-now.getHours();
var mins = 60-now.getMinutes();
var secs = 60-now.getSeconds();
timeLeft = "You now have "+hrs+' hours '+mins+' minuts '+secs+' seconds' +" To ensure delivery within 24 hours";
$("#countdown").html(timeLeft);
}
var countdown;
function StopTime() {
clearInterval(countdown);
}
setInterval(ShowTime ,1000);
函数ShowTime(){
var now=新日期();
var hrs=18 now.getHours();
var mins=60 now.getMinutes();
var secs=60 now.getSeconds();
timeLeft=“您现在有“+hrs+‘hours’+mins+‘minuts’+secs+‘secs’+”确保在24小时内交货”;
$(“#倒计时”).html(timeLeft);
}
var倒计时;
函数StopTime(){
清除间隔(倒计时);
}
设置间隔(显示时间,1000);
多谢各位
Martin计数器只会变为负数,介于1900和0000之间-因此为hrs变量创建if语句就足够了。在本声明中,您决定从18(或您的截止日期)或从18+24减去:
function ShowTime() {
var now = new Date();
if (now.getHours() > 18){
var hrs =18-now.getHours() +24;
}else{
var hrs = 18-now.getHours();
}
var mins = 60-now.getMinutes();
var secs = 60-now.getSeconds();
timeLeft = "You now have "+hrs+' hours '+mins+' minuts '+secs+' seconds' +" To ensure delivery within 24 hours";
$("#countdown").html(timeLeft);
}
更新您的小提琴:谢谢您的回复。我要找的是一个计数器,它会自动复位到24小时,然后计数23:59,23:58等等。。。所以基本上,它应该不断地从12数到12。你可以尝试一下,把18改成比实际时间低的任何值。在我的情况下,这将是11(不要忘记批准解决方案;)我在这里添加了正确时间的代码,并添加了丹麦语文本。它需要支持一些新特性。在周末(星期六和星期日),应计算到星期一11.00。那么圣日呢?嗯,这将是一个新问题。。。而且你至少需要一个休息日列表——最好是一个日历插件——来获得所有的休息日,每天24小时在线休息。。。