首页 > Web开发 > 详细

js倒计时

时间:2016-09-07 15:53:03      阅读:186      评论:0      收藏:0      [点我收藏+]

<!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>

js倒计时

原文:http://www.cnblogs.com/shaohaixiong/p/5849717.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!