前面寫過一個單點的倒計時代碼,現(xiàn)在團購網(wǎng)上經(jīng)常有多個倒計時,于是對原來代碼進行修改,做個多點倒計時代碼
效果:單點倒計時查看 團購倒數(shù)計時代碼
效果:多點倒計時查看 團購倒數(shù)計時代碼
代碼如下:
<DIV id=foraspcn></DIV>
<DIV id=foraspcn2></DIV>
<DIV id=foraspcn3></DIV>
<SCRIPT language=javascript>
var datego_arr = new Array("2018-10-09 21:35:28","2013-10-08 21:22:28","2010-10-07 21:35:58");//這里是對應的時間
var divobj_arr = new Array("foraspcn","foraspcn2","foraspcn3");//這里是對應的顯示內(nèi)容的對象id
function forasp_cn_date(){
for(var i=0;i<datego_arr.length;i++){
var datego = datego_arr[i];
var datetemp = (datego.replace(/:| /g,"-")).split("-");
var t =(new Date(Date.UTC(datetemp[0],datetemp[1]-1,datetemp[2],datetemp[3]-8,datetemp[4],datetemp[5]))).getTime();
var datego_u = t/1000;
var now_u = (new Date()).valueOf()/1000;
var forasp_cn = datego_u-now_u;
if(forasp_cn>0){
var day = Math.floor(forasp_cn/(24*3600));
var hour = Math.floor((forasp_cn-day*24*3600)/3600);
var minter = Math.floor((forasp_cn-day*24*3600-hour*3600)/60);
var secound = Math.floor(forasp_cn-day*24*3600-hour*3600-minter*60);
var mimse = Math.floor((forasp_cn-day*24*3600-hour*3600-minter*60-secound)*10);
document.getElementById(divobj_arr[i]).innerHTML=("倒計時"+day+"天"+hour+"時"+minter+"分"+secound+"."+mimse+"秒");
}else{
document.getElementById(divobj_arr[i]).innerHTML=("已經(jīng)過期了!");
}
}
}
setInterval(forasp_cn_date,100);
</SCRIPT>
更多信息請查看IT技術專欄