码迷,mamicode.com
首页 > Web开发 > 详细

js倒记时代码开发

时间:2018-03-07 11:44:28      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:倒记时代码

<!DOCTYPE html> <html> <head> <meta charset="utf-8" > <title></title> </head> <body onload="leftTimer()"> <h2>投标倒记时:</h2> <table> <tr> <td id="days" style=" color: #000;"></td> <td id="hours"></td> <td id="minutes"></td> <td id="seconds"></td> </tr> </table> <style type="text/css"> td{ background: #1e7bb3; padding: 0 10px; height: 50px; line-height: 50px; font-size: 30px; color: #fff; font-weight: bold;} </style> </body> </html> <script language="javascript" type="text/javascript"> var itimer=null; function checkTime(i){ //将0-9的数字前面加上0,例1变为01 if(i <1) { return "00"; } else { if(i<10) { i = "0" + i; } return i; } } function c(a) { console.log(a); } function leftTimer(year,month,day,hour,minute,second){ var leftTime = (new Date(year,month-1,day,hour,minute,second)) - (new Date()); //计算剩余的毫秒数 var days = parseInt(leftTime / 1000 / 60 / 60 / 24 , 10); //计算剩余的天数 var hours = parseInt(leftTime / 1000 / 60 / 60 % 24 , 10); //计算剩余的小时 var minutes = parseInt(leftTime / 1000 / 60 % 60, 10);//计算剩余的分钟 var seconds = parseInt(leftTime / 1000 % 60, 10);//计算剩余的秒数 var seconds11=seconds; days = checkTime(days); hours = checkTime(hours); minutes = checkTime(minutes); seconds = checkTime(seconds); document.getElementById("days").innerHTML = days+"天"; document.getElementById("hours").innerHTML = hours+"小时"; document.getElementById("minutes").innerHTML = minutes+"分"; document.getElementById("seconds").innerHTML = seconds+"秒"; //清除定时器任务 if(seconds11 < 0) { clearInterval(itimer); } c(leftTime); } window.onload = function(){ itimer= setInterval("leftTimer(2018,03,07,10,30,00)",1000); } </script>

js倒记时代码开发

标签:倒记时代码

原文地址:http://blog.51cto.com/771541213/2083720

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