【发布时间】:2017-10-22 20:35:24
【问题描述】:
http://jsfiddle.net/8Ab78/448/
我试图修复它但失败了。
function ShowTime() {
var now = new Date();
var tomorrow = new Date();
tomorrow.setDate(today.getDate() + 1);
var hrs = 17 - now.getHours();
var mins = 30 - now.getMinutes();
var secs = 60 - now.getSeconds();
if (hrs < 0) {
var hrs = 17 - tomorrow.getHours();
var mins = 30 - tomorrow.getMinutes();
var secs = 60 - tomorrow.getSeconds();
}
timeLeft = "" + hrs + ' hours ' + mins + ' minutes ' + secs + ' seconds';
$("#countdown").html(timeLeft);
}
ShowTime();
var countdown = setInterval(ShowTime, 1000);
<div id="countdown"></div>
【问题讨论】:
-
显示的代码根本没有运行,因为
today变量没有定义。无论如何,如果您想倒计时到零并停在那里,那么您需要在那个时候致电clearInterval()。 -
你还想完成什么?
-
@nnnnnn — 从代码看来,OP 不希望它停在零处,而是开始倒计时到“明天”的 17:00(对分钟和秒进行一些不寻常的调整)。
标签: javascript countdown clock