<p>functioncountDown(times,fn,endFn){if(typeoftimes==="number"){times=calculateTime(times);}elseif(Object.prototype.toString.apply(times)==="[objectDate]"){times=calculateTime(times.getTime()-newDate().getTime());}fn(times);//一开始先执行一次varintervalMac=setInterval(function(){vartimesLen=times.length,scales=[24,60,60],scalesLen=scales.length;for(vari=timesLen;i--;){if(times[i]>0){times[i]=times[i]-1;break;}//等于0,非首位的处理if(i!==0){times[i]=scales[scalesLen-(timesLen-i)]-1;}else{//一直到首位都为0,倒计时结束for(varj=0;j<times.length;j++){times[j]=0;}clearInterval(intervalMac);return;}}fn(times);if(typeofendFn==="function"){varisEnd=true;for(vari=0,len=times.length;i<len;i++){if(times[i]!==0){isEnd=false;break;}}if(isEnd){endFn(times);}}},1000);}//把毫秒转换成数组[day,hour,minute,second]functioncalculateTime(time){if(time<0){return[0,0,0,0];}time=Math.floor(time/1000);vartimes=[],scales=[86400,3600,60];for(vari=0;i<scales.length;i++){times.push(Math.floor(time/scales[i]));time%=scales[i];}times.push(time);returntimes;}使用方法:</p><p>1、countDown(132000,function(data){varhtmStr='<pclass="lowtitle">倒计时还剩</p>'+'<spanclass="red">'+data[0]+'</span>天 '+'<spanclass="red">'+data[1]+'</span>小时 '+'<spanclass="red">'+data[2]+'</span>分 '+'<spanclass="red">'+data[3]+'</span>秒 ';fish.all("#countDown").html(htmStr);},function(){alert("over");});2、countDown([1,5,41],function(arr){varhtmStr='<pclass="lowtitle">倒计时还剩</p>'+'<spanclass="red">'+arr[0]+'</span>小时 '+'<spanclass="red">'+arr[1]+'</span>分 '+'<spanclass="red">'+arr[2]+'</span>秒 ';fish.all("#countDown").html(htmStr);});效果:本文由免费劳务派遣系统软件系统起航劳务派遣系统原创,转载请注明出处。</p>