js实现倒计时

<!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=gb2312" />
<title>倒计时测试</title>
</head>

<body>
答题记时:
<INPUT id=cz type=hidden value=1>
<INPUT class=inp id=h readOnly size=4 value=0 name=h>时
<INPUT class=inp id=m readOnly size=4 value=1 name=m>分
<INPUT class=inp id=s readOnly size=4 value=0 name=s>秒
<br/>
<script language=
"javascript" type="text/javascript">
var cz=document.getElementById(
"cz");
function show_date_time(){
var h=document.getElementById(
"h");
var m=document.getElementById(
"m");
var s=document.getElementById(
"s");
if(cz.value==1){
window.setTimeout(
"show_date_time()",1000);
}else{
return;
}
s.value=s.value-1;
if(s.value<=0){
if(m.value>=1){
m.value=m.value-1;
s.value=59;
}else{
s.value=0;
}

}
if(m.value<=0){
if(h.value>=1){
h.value=h.value-1;
m.value=59;
}else{
m.value=0;
}
}
if(h.value<=0){
h.value=0;
}
if(h.value<=0&&m.value<=0&&s.value<=0){
alert('您的答题时间到了,系统自动交卷');
return;
}
}
show_date_time();

function stop_time(){
var mi=document.getElementById(
"mi");
if(cz.value==1){
cz.value=0;
mi.value=
"继续"
}else{
cz.value=1;
mi.value=
"暂停";
show_date_time()
}
}
</script>

<input type=
"button" id="mi" value="暂停" onclick="stop_time()" />

</body>
</html>
lunzi   2007-11-06 22:25:11 评论:0   阅读:109   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2008 powered by YuLog