var Cookie = {
    get:function(key){
        var reg = new RegExp('(?:^| )' + key + '=([^;]+)(?=;|$)','gi');
        return (result = document.cookie.match(reg)) == null ? null : decodeURIComponent(result[1]);
    },
    set:function(key,value,expireHours,path,domain,secure){
        var path = path || '/',
            domain = domain || location.host,
            cookie = [key + '=' + encodeURIComponent(value),'path=' + path,'domain='+domain];
        if(expire){
            cookie.push('expires=' + this.hoursToExpire(expireHours))
        }
        if(secure){
            cookie.push(secure)
        }
        document.cookie = cookie.join('');
        return document.cookie;
    },
    del:function(key){
        if(this.get(key)){var expire = new Date();
            expire.setTime(now.getTime() - 10000);
            this.set(key,'',expire,path,domain);
        }
    },
    hoursToExpire:function(hours){
        if(parseInt(hours) == NaN){
            return '';
        }
        var now = new Date();
        now.setTime(now.getTime() + parseInt(hours)*60*60*1000);
        return now.toGMTString();
    }
}

 

相关文章:

  • 2022-12-23
  • 2022-02-15
  • 2021-10-25
  • 2021-12-03
  • 2021-10-27
  • 2022-12-23
  • 2021-09-27
猜你喜欢
  • 2022-12-23
  • 2021-12-02
  • 2021-11-22
  • 2021-07-16
  • 2022-12-23
  • 2021-11-22
  • 2021-07-25
相关资源
相似解决方案