所以我在 counter.js 中有这段代码
month= --month;
dateFuture = new Date(year,month,day,hour,min,sec);
dateFuture2 = new Date(year2,month2,day2,hour2,min2,sec2);
function GetCount(){
dateNow = new Date();
amount = dateFuture.getTime() - dateNow.getTime()+5;
delete dateNow;
/* time is already past */
if(amount < 0){
out=
"<div id='days'><span></span><p>0</p><div id='days_text'></div></div>" +
"<div id='hours'><span></span><p>0</p><div id='hours_text'></div></div>" +
"<div id='mins'><span></span><p>0</p><div id='mins_text'></div></div>" +
"<div id='secs'><span></span><p>0</p><div id='secs_text'></div></div>" ;
document.getElementById('countbox').innerHTML=out;
}
/* date is still good */
else{
days=0;hours=0;mins=0;secs=0;out="";
amount = Math.floor(amount/1000); /* kill the milliseconds */
days=Math.floor(amount/86400); /* days */
amount=amount%86400;
hours=Math.floor(amount/3600); /* hours */
amount=amount%3600;
mins=Math.floor(amount/60); /* minutes */
amount=amount%60;
secs=Math.floor(amount); /* seconds */
out=
"<div id='days'><span></span><p>" + days +"</p><div id='days_text'></div></div>" +
"<div id='hours'><span></span><p>" + hours +"</p><div id='hours_text'></div></div>" +
"<div id='mins'><span></span><p>" + mins +"</p><div id='mins_text'></div></div>" +
"<div id='secs'><span></span><p>" + secs +"</p><div id='secs_text'></div></div>" ;
document.getElementById('countbox').innerHTML=out;
setTimeout("GetCount()", 1000);
}
}
month= --month;
dateFuture = new Date(year,month,day,hour,min,sec);
dateFuture2 = new Date(year2,month2,day2,hour2,min2,sec2);
function GetCount2(){
dateNow = new Date();
amount = dateFuture2.getTime() - dateNow.getTime()+5;
delete dateNow;
/* time is already past */
if(amount < 0){
out=
"<div id='days2'><span></span><p>0</p><div id='days_text'></div></div>" +
"<div id='hours2'><span></span><p>0</p><div id='hours_text'></div></div>" +
"<div id='mins2'><span></span><p>0</p><div id='mins_text'></div></div>" +
"<div id='secs2'><span></span><p>0</p><div id='secs_text'></div></div>" ;
document.getElementById('countbox2').innerHTML=out;
}
/* date is still good */
else{
days=0;hours=0;mins=0;secs=0;out="";
amount = Math.floor(amount/1000); /* kill the milliseconds */
hours=Math.floor(amount/499600); /* hours */
amount=amount%3600;
mins=Math.floor(amount/60); /* minutes */
amount=amount%60;
secs=Math.floor(amount); /* seconds */
out=
"<div id='days2'><span></span><p>" + days +"</p><div id='days_text'></div></div>" +
"<div id='hours2'><span></span><p>" + hours +"</p><div id='hours_text'></div></div>" +
"<div id='mins2'><span></span><p>" + mins +"</p><div id='mins_text'></div></div>" +
"<div id='secs2'><span></span><p>" + secs +"</p><div id='secs_text'></div></div>" ;
document.getElementById('countbox2').innerHTML=out;
setTimeout("GetCount2()", 1000);
}
}
window.onload=function(){GetCount(); GetCount2();}
我在 index.html 中有这个代码来给出具体时间的日期,在这种情况下两者都是相同的
<!-- Enter countdown here -->
<script type="text/javascript">
//Edit data below to your personal preferences ----------------------------------
//Give the date ---------------------------------
year = 2015; year2 = 2015;
month = 12; month2 = 12;
day = 12; day2 = 12;
//Give the point of time ------------------------
hour= 24; hour2 = 24;
min= 0; min2 = 0;
sec= 0; sec2 = 0;
//-----------------------------------------------
//That's it!
这会触发 index.html 中的两个倒计时
<!-- Countdown -->
<div id="countdown">
<div class="event-title">
</div>
<div id="countbox"></div>
<div class="event-title"></div>
</div>
<div id="countdown2">
<div class="event-title">
</div>
<div id="countbox2"></div>
<div class="event-title"></div>
</div>
倒计时在那里并且正在倒计时,但由于某种原因,第二个计数器没有任何天,它只显示为零,它只显示多少小时,有人知道我为什么会遇到这个问题吗?我经历了一切,我显然错过了一些重要的事情。
感谢您的任何帮助。