[javascript]代码库
<script type="text/javascript">
var second=10;
var timer;
function change()
{
second--;
if(second>-1)
{
document.getElementById("second").innerHTML=second;
timer = setTimeout('change()',1000);//调用自身实现
}
else
{
clearTimeout(timer);
}
}
timer = setTimeout('change()',1000);
</script>
<script type="text/javascript">
<!--
//一个小时,按秒计算,可以自己调整时间
var maxtime = 60*60
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 == 5*60) alert('注意,还有5分钟!');
--maxtime;
}
else
{
clearInterval(timer);
alert("时间到,结束!");
}
}
timer = setInterval("CountDown()",1000);
//-->
</script>