有个复选框,如果选中复选框,就自动刷新,如果不想自动刷新了,就去掉复选框

解决方案 »

  1.   


    <script>
    var tid, cookie;
    String.prototype.Trim = function()
      {
          return this.replace(/^\s+/g,"").replace(/\s+$/g,"");
      }
      
      function JSCookie()
      {
          this.GetCookie = function(key)
          {
            var cookie = document.cookie;
            var cookieArray = cookie.split(';');
            var getvalue = "";
            for(var i = 0;i<cookieArray.length;i++)
            {
                
                if(cookieArray[i].Trim().substr(0,key.length) == key)
                {
                    getvalue = cookieArray[i].Trim().substr(key.length + 1);
                    break;
                }
            }        return getvalue;
        };
        this.GetChild = function(cookiekey,childkey)
        {
            var child = this.GetCookie(cookiekey);
            var childs = child.split('&');
            var getvalue = "";
            
            for(var i = 0;i < childs.length;i++)
            {
                if(childs[i].Trim().substr(0,childkey.length) == childkey)
                {
                    getvalue = childs[i].Trim().substr(childkey.length + 1);
                    break;
                }
            }
            return getvalue;
        };
        this.SetCookie = function(key,value,expire,domain,path)
        {
            var cookie = "";
            if(key != null && value != null)
                cookie += key + "=" + value + ";";
            if(expire != null)
                cookie += "expires=" + expire.toGMTString() + ";";
            if(domain != null)
                cookie += "domain=" + domain + ";";
            if(path != null)
                cookie += "path=" + path + ";";
            document.cookie = cookie;
        };
        this.Expire = function(key)
        {
            expire_time = new Date();
            expire_time.setFullYear(expire_time.getFullYear() - 1);
            var cookie = " " + key + "=e;expires=" + expire_time + ";"
            document.cookie = cookie;
        }
    }function doit(){
    if(tid!=null){clearTimeout(tid);tid=null}
    var ck = document.getElementById("ck")
    if(ck.checked){
    cookie.SetCookie("ck","1")
    location.reload()
    }
    else{
    cookie.SetCookie("ck","0")
    tid = setTimeout("doit()", 2000)
    }
    }
    window.onload=function(){
    cookie = new JSCookie();
    var ck = document.getElementById("ck")
    if(cookie.GetCookie("ck")=="1") ck.checked=true;
    tid = setTimeout("doit()", 2000)
    }
    </script>
    <input type="checkbox" id="ck">
      

  2.   

    写个简单滴L@_@K
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><HTML xmlns="http://www.w3.org/1999/xhtml">
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
     </HEAD> <BODY>
      <input type="checkbox" id="cbxRefresh" />自动刷新
      <script type="text/javascript">
    document.write("<br />", new Date());function refreshWin() {
    window.location.href = window.location.href;
    }var refresh = document.getElementById('cbxRefresh');
    // 刷新间隔 1000 毫秒。
    var refreshInterval = 1000;
    refresh.onclick = function() {
    if (refresh.checked) {
    this.TimerID = window.setTimeout(refreshWin, refreshInterval);
    document.cookie = "isRefresh=true";
    }
    else {
    window.clearTimeout(this.TimeoutID);
    document.cookie = "isRefresh=false";
    }
    }document.body.onload = function() {
    if(document.cookie.indexOf("isRefresh=true") > -1) {
    refresh.click();
    }
    }
      </script>
     </BODY>
    </HTML>