中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

用js控制cookie(cookie操作類)

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
function cookie(name, value, expires, path, domain, secure) {
    // 初始化
    this.name = name;
    this.value = value;
    this.expires = expires;
    this.path = path;
    this.domain = domain;
    this.secure = secure;
    
    // 讀取cookie
    this.read = function () {
        // 快捷操作
        var ck = document.cookie;
        
        var arg = this.name + "=";
        var alen = arg.length;
        var clen = ck.length;
        var i = 0;
        while (i < clen) {
            var j = i + alen;
            if (ck.substring(i, j) == arg) {
                var endstr = ck.indexOf(";", j);
                if (endstr == -1)
                    endstr = ck.length;
                return unescape(ck.substring(j, endstr));
            }
            i = ck.indexOf(" ", i) + 1;
            if (i == 0)
                break;
        }
        return null;
    }
    
    // 設置cookie
    this.set = function () {
        // 更新cookie過期時間
        expStore = this.expires;
        
        exp = new Date();
        base = new Date(0);
        skew = base.getTime();
        if (skew > 0)
            exp.setTime(exp.getTime() - skew);
        exp.setTime(exp.getTime() + (this.expires * 24 * 60 * 60 * 1000));
        this.expires = exp;
        
        document.cookie = this.name + "=" + escape(this.value) +
            ((this.expires) ? "; expires=" + this.expires.toGMTString() : "") +
            ((this.path) ? "; path=" + this.path : "") +
            ((this.domain) ? "; domain=" + this.domain : "") +
            ((this.secure) ? "; secure" : "");
        
        // 刷新cookie類中的cookie過期時間
        this.expires = expStore;
    }
    
    // 刪除cookie
    this.kill = function () {
        document.cookie = this.name + "=" +
            ((this.path) ? "; path=" + this.path : "") +
            ((this.domain) ? "; domain=" + this.domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
    
    // 更改cookie類中的cookie屬性
    this.changeName = function (chName) {
        this.kill();
        this.name = chName;
        this.set();
    }
    this.changeVal = function (chVal) {
        this.kill();
        this.value = chVal;
        this.set();
    }
    this.changeExp = function (chExp) {
        this.kill();
        this.expires = chExp;
        this.set();
    }
    this.changePath = function (chPath) {
        this.kill();
        this.path = chPath;
        this.set();
    }
    this.changeDomain = function (chDom) {
        this.kill();
        this.domain = chDom;
        this.set();
    }
    this.changeSecurity = function (chSec) {
        this.kill();
        this.secure = chSec;
        this.set();
    }
}

標簽:

版權申明:本站文章部分自網(wǎng)絡,如有侵權,請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:判斷輸入的參數(shù)是否是一個合格的身份證號碼

下一篇:判斷輸入的字符是否全部是中文字符