cookie 的简单封装
## cookie 的简单封装 写的匆忙 有不对的地方请指正
var cookies = {
set: function (name, value, flag) { // flag == fasle 不设置时间
var Days = 7;
var exp = new Date();
exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
if (!flag) {
document.cookie = name + "=" + escape(value) + ';path=/;';
} else {
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() +';path=/;';
}
},
get: function (name) {
var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
if (arr = document.cookie.match(reg))
return unescape(arr[2]);
else
return null;
},
del: function (name) {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = this.get(name);
if (cval != null)
document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
}