前面寫過(guò)一個(gè)單點(diǎn)的倒計(jì)時(shí)代碼,現(xiàn)在團(tuán)購(gòu)網(wǎng)上經(jīng)常有多個(gè)倒計(jì)時(shí),于是對(duì)原來(lái)代碼進(jìn)行修改,做個(gè)多點(diǎn)倒計(jì)時(shí)代碼
效果:?jiǎn)吸c(diǎn)倒計(jì)時(shí)查看 團(tuán)購(gòu)倒數(shù)計(jì)時(shí)代碼
效果:多點(diǎn)倒計(jì)時(shí)查看 團(tuán)購(gòu)倒數(shù)計(jì)時(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");//這里是對(duì)應(yīng)的時(shí)間
var divobj_arr = new Array("foraspcn","foraspcn2","foraspcn3");//這里是對(duì)應(yīng)的顯示內(nèi)容的對(duì)象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=("倒計(jì)時(shí)"+day+"天"+hour+"時(shí)"+minter+"分"+secound+"."+mimse+"秒");
}else{
document.getElementById(divobj_arr[i]).innerHTML=("已經(jīng)過(guò)期了!");
}
}
}
setInterval(forasp_cn_date,100);
</SCRIPT>
更多信息請(qǐng)查看IT技術(shù)專欄