码迷,mamicode.com
首页 > 其他好文 > 详细

cookie

时间:2014-08-27 00:13:06      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   div   cti   log   sp   

GLOBAL.namespace(‘Cookie‘);
GLOBAL.Cookie = {
    //读取
    read : function(name) {
        var cookieStr = ‘; ‘ + document.cookie + ‘; ‘;
        var index = cookieStr.indexOf(‘; ‘ + name + ‘=‘);
        if (index != -1){
            var s = cookieStr.substring(index + name.length + 3, cookieStr.length);
            return unescape(s.substring(0, s.indexOf(‘; ‘)));
        } else {
            return null;
        }
    };

    // 设置
    set : function(name, value, expires) {
        var expDays = expires * 24 * 60 * 60 * 1000;
        var expDate = new Date();
        expDate.setTime(expDate.getTime() + expDays);
        var expString = expires ? ‘; expires=‘ + expDate.toGMTString() : ‘‘;
        var pathString = ‘;path = /‘;
        document.cookie = name + ‘=‘ + escape(value) + expString + pathString;
    };

    // 删除
    del : function(name) {
        var exp = new Date(new Date().getTime() - 1);
        var s = this.read(name);
        if (s != numm){
            document.cookie = name + ‘=‘ + s +‘;expires = ‘ + exp.toGMTString() + ‘;path = /‘
        };
    }
};

 

cookie

标签:style   blog   color   io   ar   div   cti   log   sp   

原文地址:http://www.cnblogs.com/baixc/p/3938428.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!