js倒计时

//js倒计时,废话不多说,贴代码

<html>

<head>

<scripttype="text/javascript">

var maxtime = 2*60*60 //一个小时,按秒计算,自己调整!

function CountDown(){

if(maxtime>=0){

hours
=Math.floor(maxtime/3600)

minutes
= Math.floor((maxtime-3600*hours)/60);

seconds
= Math.floor(maxtime%60);

msg
= "距离结束还有:"+hours+""+minutes+""+seconds+"";

document.getElementById(
"timer").innerHTML=msg;

if(maxtime == 5*60) alert('注意,还有分钟!');

--maxtime;

}
else{

clearInterval(timer);

alert(
"时间到,结束!");

}

}

timer
= setInterval("CountDown()",1000);

</script>



</head>

<body>

<divid="timer"></div>

</body>

</html>



posted @ 2012-03-30 19:24  WebApi  阅读(437)  评论(0编辑  收藏  举报
CopyRight © 博客园 WebAPI