定时器
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<h1 id="obj1"></h1>
<script>
var cnt=5000;
function f1(){
cnt--;
var obj1=document.getElementById("obj1");
if(cnt==0){
obj1.innerHTML="定时结束";
}else{
var h=parseInt(""+cnt/3600);
var m=parseInt(""+cnt%3600/60);
var s=cnt%60;
h=h<10?"0"+h:h;
m=m<10?"0"+m:m;
s=s<10?"0"+s:s;
obj1.innerHTML=h+":"+m+":"+s;
setTimeout(f1,1000);
}
}
f1();
</script>
</body>
</html>
posted on 2015-11-02 17:29 kebizhanmushi 阅读(84) 评论(0) 编辑 收藏 举报