JS操作倒计时代码
<script type ="text/javascript" >
<!--
var time="3600";
var atime="300";
var etime="0";
function count(){
setTimeout("count()",1000);
document.form1.rest.value=format(Math.floor(time/60))+"分:"+format(time%60)+"秒";
time--;
if(time==atime){
alert("还剩5分钟");
}
if(time==etime-1){
alert("时间到,已经自动提交");
document.form1.submit();
}
}
function format(time){
var len=time.toString().length;
for(i="0";i<2-len;i++){
time="0"+time;
}
return time;
}
//-->
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" value="开始" onclick="count();this.disabled=true"/>
<input type="text" name="rest" value="60分:00秒"/>
</div>
</form>
<!--
var time="3600";
var atime="300";
var etime="0";
function count(){
setTimeout("count()",1000);
document.form1.rest.value=format(Math.floor(time/60))+"分:"+format(time%60)+"秒";
time--;
if(time==atime){
alert("还剩5分钟");
}
if(time==etime-1){
alert("时间到,已经自动提交");
document.form1.submit();
}
}
function format(time){
var len=time.toString().length;
for(i="0";i<2-len;i++){
time="0"+time;
}
return time;
}
//-->
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" value="开始" onclick="count();this.disabled=true"/>
<input type="text" name="rest" value="60分:00秒"/>
</div>
</form>