js倒计时

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="Keywords" content="关键字,关键字">
<meta name="Author" content="邵海雄">
<meta name="Description" content="描述信息">
<title>Document</title>
<style type="text/css">
*{margin:0;padding:0;}
</style>
</head>
<body>
<div id="rest_time"></div>
<script type="text/javascript">
var sec =3,min=0,hour =1;
var idt = window.setInterval("time();", 1000);
//时间格式 如:1-9 为 01-09
var format = function(str){
if(parseInt(str) < 10){
return "0" + str;
}
return str;
};
//倒计时
function time() {
sec--;
if(sec ==0 && min>0){
min--;
sec = 59;
}
if(min <0 && hour >0){
hour--;
min = 59;
}
document.getElementById("rest_time").innerText = format(hour) + ":" + format(min) + ":" + format(sec);
if (parseInt(hour)<=0&&parseInt(min)<=0&&parseInt(sec)<=0) {
window.clearInterval(idt);
alert('考试时间已到,试卷已提交,感谢使用本系统!');
}
}
</script>
</body>
</html>

posted on 2016-09-07 15:41  邵海雄  阅读(181)  评论(0编辑  收藏  举报

导航