-4

每次我重新加载此页面http://prince27.bplaced.net/Prince27-Website/html/slider_true.html时,倒计时都会重新开始。我做错了什么?

我已将 endDate 设置为 2012 年 9 月 20 日,并计算了 now 和 endDate 之间的毫秒数。

var today = new Date();

var endDate = new Date("20/09/2012"); //set the date you want timer to end
var diffMs = (280800000); // milliseconds between now & endDate
var diffDays = Math.round(diffMs / 86400000); // days
var diffHrs = Math.round((diffMs % 86400000) / 3600000); // hours
var diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); // minutes
var diffSecs = Math.floor((((diffMs % 86400000) % 3600000) % 60000) / 1000);

完整的脚本文件

4

2 回答 2

5

您已经硬编码了差异:

var diffMs = (280800000); // milliseconds between now & endDate
于 2012-09-17T13:58:32.977 回答
3

检查你的代码,你有硬编码的价值diffMs,你从不使用today

var today = new Date();

var endDate = new Date("20/09/2012"); //set the date you want timer to end
var diffMs = (280800000); // milliseconds between now & endDate
于 2012-09-17T13:59:13.867 回答