点击按钮出现60秒倒计时js代码
html
<div class="img_font" id="2_time">距离结束: 00:00:00</div> <div class="money_font" id="mo_time2">已结束</div>
js
<script type="text/javascript"> var interval = 1000; function ShowCountDown(year,month,day,hour,divname,moname,number) { var now = new Date(); var endDate = new Date(year, month-1, day,hour); var leftTime=endDate.getTime()-now.getTime(); var leftsecond = parseInt(leftTime/1000); var day1=Math.floor(leftsecond/(60*60*24)); var hour=Math.floor((leftsecond-day1*24*60*60)/3600); var minute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60); var second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60); var cc = document.getElementById(divname); var dd= document.getElementById(moname); minute=checkTime(minute); second=checkTime(second); if(leftTime<=0){ dd=innerHTML= "已结束"; // cc.innerHTML = "距离结束: "+hour+":"+minute+":"+second; return ; } cc.innerHTML = "距离结束: "+hour+":"+minute+":"+second; if(number>0){ dd.style.cssText="background-color: red;"; dd.innerHTML= "已抢"+number; } } function checkTime(i) { if (i<10) {i="0" + i} return i } setInterval(function(){ ShowCountDown(2017,12,4,18,'1_time','mo_time1',0); ShowCountDown(2017,12,4,17,'2_time','mo_time2',123); ShowCountDown(2017,12,4,20,'3_time','mo_time3',324); ShowCountDown(2017,12,4,21,'4_time','mo_time4',534); }, interval); </script>