码迷,mamicode.com
首页 > 其他好文 > 详细

倒计时

时间:2017-11-16 11:51:10      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:bsp   return   html   floor   col   inner   second   day   cti   

 1     function ShowCountDown(year,month,day,hours,mintes,seconds,divname) {
 2         function c(xx) {
 3             if(xx<0){
 4                 return 0
 5             }else{
 6                 return (xx<10)?‘0‘+xx:xx;
 7             }
 8         }
 9         var now = new Date();
10         var endDate = new Date(year, month-1, day,hours,mintes,seconds);
11         var leftTime=endDate.getTime()-now.getTime();
12         var leftsecond = parseInt(leftTime/1000);
13 //var day1=parseInt(leftsecond/(24*60*60*6));
14         var day1=Math.floor(leftsecond/(60*60*24));
15         var hour=Math.floor((leftsecond-day1*24*60*60)/3600);
16         var minute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60);
17         var second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60);
18         var cc = document.getElementById(divname);
19         function f(day1,time) {/*负数时间*/
20                 if(day1<0){
21                     return 0
22                 }else{
23                     return (time<10)?‘0‘+time:time;
24                 }
25         }
26         cc.innerHTML = ‘<p class="day">‘+c(day1)+‘天</p>‘+‘<p class="time">‘+f(day1,hour)+"小时"+f(day1,minute)+"分"+f(day1,second)+"秒"+‘</p>‘;
27     }

//调用

var interval = 1000;
    window.setInterval(function(){ShowCountDown(2018,1,15,17,00,00,‘time1‘);}, interval);

 

倒计时

标签:bsp   return   html   floor   col   inner   second   day   cti   

原文地址:http://www.cnblogs.com/NB-JDzhou/p/7842699.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!