效果:给定一个总时间,当时间倒计到最后10分钟的时间提醒用户还剩10分钟
<script language="JavaScript">
<!--
t=10; //总时间
var maxtime;
if(window.name==''){
maxtime = t*60;
}else{
maxtime = window.name;
}
function CountDown(){
if(maxtime>=0){
minutes = Math.floor(maxtime/60);
seconds = Math.floor(maxtime%60);
msg = "距离结束还有"+minutes+"分"+seconds+"秒";
document.all["timer"].innerHTML = msg;
if(maxtime == t*60) alert('注意,还有10分钟!'); //提醒时间
--maxtime;
window.name = maxtime;
}
else{
clearInterval(timer);
alert("时间到,结束!");
}
}
timer = setInterval("CountDown()",1000);
//-->
</script><div id="timer" style="color: red;"></div>
<script language="JavaScript">
<!--
t=10; //总时间
var maxtime;
if(window.name==''){
maxtime = t*60;
}else{
maxtime = window.name;
}
function CountDown(){
if(maxtime>=0){
minutes = Math.floor(maxtime/60);
seconds = Math.floor(maxtime%60);
msg = "距离结束还有"+minutes+"分"+seconds+"秒";
document.all["timer"].innerHTML = msg;
if(maxtime == t*60) alert('注意,还有10分钟!'); //提醒时间
--maxtime;
window.name = maxtime;
}
else{
clearInterval(timer);
alert("时间到,结束!");
}
}
timer = setInterval("CountDown()",1000);
//-->
</script><div id="timer" style="color: red;"></div>