<script type= "text/javascript ">
<!--
var duration=2900;
var timer=null;
var endTime = new Date().getTime() + duration + 100;
function interval()
{
var n=(endTime-new Date().getTime())/1000;
if(n <=0)
{
document.getElementById( "timeout ").innerHTML = '0.000 ';
window.location.href= "http://blog.csdn.net ";
return;
}
document.getElementById( "timeout ").innerHTML = n.toFixed(3);
timer=setTimeout(interval, 10);
}
function stopJump()
{
clearTimeout(timer);
document.getElementById( "jumphint ").style.display = "none ";
}
window.onload=function()
{
//timer=setTimeout( "window.location.href= 'http://blog.csdn.net/ ' ", duration);
interval();
}
//-->
</script>
<span id= "jumphint "> 系统在 <span id= "timeout "> 3.000 </span> 秒后 将自动 </span> 跳转到 <a href= "http://blog.csdn.net "> BLOG首页 </a> <br />
<input type= "button " value= "停止自动跳转 " onclick= "stopJump(); this.disabled=true " />
是参照这里的改的主要是把
timer=setTimeout( "window.location.href= 'http://blog.csdn.net/ ' ", duration);
换到
if(n <=0)
{
document.getElementById( "timeout ").innerHTML = '0.000 ';
window.location.href= "http://blog.csdn.net ";
return;
}
把timer换成setTimeout(interval, 10);
暂时没发现什么错误
不知道哪个更好呢
------解决方案--------------------
这哪有什么哪种好的?
看需求嘛……
timer=setTimeout( "window.location.href= 'http://blog.csdn.net/ ' ", duration);
是在duration时间后直接把页面转过去
而
if(n <=0)
{
document.getElementById( "timeout ").innerHTML = '0.000 ';
window.location.href= "http://blog.csdn.net ";
return;
}
document.getElementById( "timeout ").innerHTML = n.toFixed(3);
这些代码是展现了计数过程,即计数未结束时不断倒计数,计数结束后转过页面。