<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><body>
<script>
function countDown(maxtime, fn) {
var timer = setInterval(function() {
if (maxtime >= 0) {
minutes = Math.floor(maxtime / 60);
seconds = Math.floor(maxtime % 60);
msg = "距离结束还有" + minutes + "分" + seconds + "秒";
fn(msg);
if (maxtime == 5 * 60) alert('注意,还有5分钟!');
--maxtime;
} else {
clearInterval(timer);
fn("时间到,结束!");
}
},
1000);
}
</script>
<div id="timer1" style="color:red"></div>
<div id="timer2" style="color:red"></div>
<script>
countDown( 6,function( msg ){document.getElementById('timer1').innerHTML = msg;});
countDown( 305,function( msg ){document.getElementById('timer2').innerHTML = msg;})</script>
</body></html>