前面写过一个单点的倒计时代码,现在团购网上经常有多个倒计时,于是对原来代码进行修改,做个多点倒计时代码
效果:单点倒计时查看 团购倒数计时代码
效果:多点倒计时查看 团购倒数计时代码
代码如下:
<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");//这里是对应的显示内容的对象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=("已经过期了!");
}
}
}
setInterval(forasp_cn_date,100);
</SCRIPT>
中国足彩网信息请查看IT技术专栏