js cookie

var JzCookie = { //cookie操做
            Set: function (name, value, expireDays, domain, isRoot) {
                // 設置 名稱 值 過時天數 主域名 是否根路徑
                var dm = '', ed = '', ir = '';
                if (expireDays) {
                    var d = new Date();
                    d.setTime(d.getTime() + (expireDays * 24 * 60 * 60 * 1000));
                    ed = ";expires=" + d.toUTCString();
                    if (domain) dm = ";domain=" + domain;
                    if (isRoot) ir = ";path=/";
                }
                document.cookie = name + "=" + escape(value) + dm + ed + ir;
            },
            Get: function (name) {
                // 獲取
                var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
                return (arr = document.cookie.match(reg)) ? arr[2] : null;
            },
            Remove: function (name, domain, isRoot) {
                // 清除
                JzCookie.Set(name, '', -1, domain, isRoot);
            }
        };
相關文章
相關標籤/搜索