日期:2014-05-17  浏览次数:20808 次

大虾还请赐教啊!如何在刷新真个页面的时候让一个计时器的时间继续计时而不被刷新阿啊?
没分了,大虾还请赐教啊!如何在刷新真个页面的时候让一个计时器的时间不变啊?

<input   type= "button "   id= "agree "   value= "等待时间为 "   onclick= " "> <BR>
</BODY>
</HTML>
<script   type= "text/javascript ">
    var   settime=300;
    var   i;
    var   showthis;
    document.all.agree.disabled=true;
    for(i=1;i <=settime;i++)       {
          setTimeout( "update( "+i+ ") ",i*1000);
    }
    function   update(num)   {
          if(num==settime)   {
    document.all.agree.value= "0 ";
    document.all.agree.disabled=false;
      }
      else   {
      showthis=settime-num;    
      document.all.agree.value= "等待时间为   ( "+showthis+ ")秒 ";
      }
    }
</script>

如何在刷新整个页面的时候,计时器不被刷新,还在继续呢?高手请进阿!

------解决方案--------------------
cookie!

<input type= "button " id= "agree " value= "等待时间为 " onclick= " "> <BR>
</BODY>
</HTML>
<script type= "text/javascript ">
var settime,exp=300;
if(!getCookie( "t "))
{
setCookie( "t ",exp,1);//设置1天后过期
settime=exp;
}
else
settime=getCookie( "t ");

document.all.agree.disabled=true;
for(i=1;i <=settime;i++) {
setTimeout( "update( "+i+ ") ",i*1000);
}
function update(num) {
if(num==settime) {
document.all.agree.value= "0 ";
document.all.agree.disabled=false;
}
else {
showthis=settime-num;
document.all.agree.value= "等待时间为 ( "+showthis+ ")秒 ";
setCookie( "t ",showthis,1);
}
}
//设置COOKIE
function setCookie(name,value,expires)
{
var expDays = expires*24*60*60*1000;
var expDate = new Date();
expDate.setTime(expDate.getTime()+expDays);
var expString = ((expires==null) ? " " : ";expires= "+expDate.toGMTString())
document.cookie = name + "= " + escape(value) + expString ;
}
//获取指定名称的cookie值
function getCookie(name)
{
var value = null;
var myCookie = document.cookie + "; ";
var searchName = name + "= ";
var startOfCookie = myCookie.indexOf(searchName);
var endOfCookie;
if (startOfCookie != -1)
{
startOfCookie += searchName.length;
endOfCookie = myCookie.indexOf( "; ",startOfCookie);
value = unescape(myCookie.substring(startOfCookie, endOfCookie));
}
return value;
}


</script>