标签:倒记时代码
<!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>
标签:倒记时代码
原文地址:http://blog.51cto.com/771541213/2083720