Javascript Countdown不起作用

时间:2012-09-17 13:54:50

标签: javascript

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

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

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);

完整脚本file

2 个答案:

答案 0 :(得分:5)

你已经硬编码了差异:

var diffMs = (280800000); // milliseconds between now & endDate

答案 1 :(得分: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