<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body onload="aa()">
<span id="aa"></span>
</body>
<script>
function aa(){
var ss=2;
var tt = setInterval(promote,1000);
function promote(){
var fen=Math.floor(ss/60);
var miao=Math.floor((ss-fen*60)%60);
fen = checkTime(fen);
miao = checkTime(miao);
var html=fen+':'+miao;
document.getElementById('aa').innerHTML=html;
ss != 0 ? (ss--) : clearInterval(tt);
console.log(1);
}
function checkTime(i){
var i;
if(i<10)
{
i = "0" + i;
}
return i;
}
}
</script>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body onload="leftTimer()">
<h2>剩余时间:</h2>
<div id="timer"></div>
</body>
<script>
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);
days = checkTime(days);
hours = checkTime(hours);
minutes = checkTime(minutes);
seconds = checkTime(seconds);
setInterval("leftTimer(2017,12,15,11,11,11)",1000);
document.getElementById("timer").innerHTML = days+"天" + hours+"小时" + minutes+"分"+seconds+"秒";
}
function checkTime(i){
if(i<10)
{
i = "0" + i;
}
return i;
}
</script>
</html>