我工作的這個倒計時的結果是:我的倒計時,這樣的數量總是http://apps.facebook.com/tjdcountdown/需要幫助對準一個JavaScript的倒計時
我想補充一個特定的寬度爲每個結果(分鐘,小時,天)完全符合下面的文字。
是否有可能爲每個結果創建一個變量並稍後在我的html代碼中調用它們?
這裏是倒計時腳本:
<script type="text/javascript">
var myMonth = "<?= $myMonth ?>";
var myDay = "<?= $myDay ?>";
var myYear = "<?= $myYear ?>";
var myHour = "<?= $myHour ?>";
var myMin = "<?= $myMin ?>";
dateFuture1 = new Date(2013,03,26,14,15,00);
function GetCount(ddate,iid){
dateNow = new Date(); //grab current date
amount = ddate.getTime() - dateNow.getTime(); //calc milliseconds between dates
delete dateNow;
// if time is already past
if(amount < 0){
document.getElementById(iid).innerHTML="I'm now married!";
}
// else date is still good
else{
years=0;weeks=0;days=0;hours=0;mins=0;secs=0;out="";
amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs
years=Math.floor(amount/31536000);//years (no leapyear support)
amount=amount%31536000;
weeks=Math.floor(amount/604800);//weeks
amount=amount%604800;
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 += years +""+((years==1)?"":"")+"";
out += weeks +""+((weeks==1)?"":"")+"";
if(days != 0){out += days +""+((days==1)?"":"")+"";}
if(hours != 0){out += hours +""+((hours==1)?"":"")+"";}
out += mins +""+((mins==1)?"":"")+"";
out += secs +""+((secs==1)?"":"")+", ";
out = out.substr(0,out.length-2);
document.getElementById(iid).innerHTML=out;
setTimeout(function(){GetCount(ddate,iid)}, 1000);
}
}
window.onload=function(){
GetCount(dateFuture1, 'countbox1');
//you can add additional countdowns here (just make sure you create dateFuture2 and countbox2 etc for each)
};
</script>
感謝了很多幫助!
+1 //'殺了毫秒' – pixelbobby 2011-05-31 17:33:41