倒计时代码
Posted jasonduanmu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了倒计时代码相关的知识,希望对你有一定的参考价值。
<script language="javascript" type="text/javascript"> var interval = 1000; function toDb(n){ if(n<10){ return ‘0‘+n; } else { return ‘‘+n; } }; function ShowCountDown(year,month,day,divname) { var now = new Date(); var endDate = new Date(year, month-1, day); var leftTime=endDate.getTime()-now.getTime(); var leftsecond = parseInt(leftTime/1000); var day1=toDb(Math.floor(leftsecond/(60*60*24))); var hour=toDb(Math.floor((leftsecond-day1*24*60*60)/3600)); var minute=toDb(Math.floor((leftsecond-day1*24*60*60-hour*3600)/60)); var second=toDb(Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60)); var cc = document.getElementById(divname); cc.innerhtml = "距离活动结束,仅剩下 <span class=‘red‘>"+day1+"</span>天 <span class=‘red‘>"+hour+"</span>时 <span class=‘red‘>"+minute+"</span>分 <span class=‘red‘>"+second+"</span>秒"; }; window.setInterval(function(){ShowCountDown(2016,10,15,‘lastTime‘);}, interval); </script>
以上是关于倒计时代码的主要内容,如果未能解决你的问题,请参考以下文章