我用js函数设置Cookie成功,但是获取不到,undefined
能获取到个别的cookie,大多数获取不到,不知道什么原因
能获取到个别的cookie,大多数获取不到,不知道什么原因
2018-01-05
var Cookie = {
set: function (key, val, expiresDays) {
if (expiresDays) {
var date = new Date();
date.setTime(date.getTime() + expiresDays * 24 * 3600 * 1000);
var expiresStr = "expires=" + date.toUTCString() + ':';
} else {
var expiresStr = '';
}
document.cookie = key + '=' + escape(val) + ';' + expiresStr;
},
get: function (key) {
var getCookie = document.cookie.replace(/[ ]/g, '');
var resArr = getCookie.split(';');
var res;
for (var i = 0, len = resArr.length; i < len; i++) {
var arr = resArr[i].split('=');
if (arr[0] == key) {
res = arr[1];
break;
}
}
return unescape(res);
}
};
试试看 toGMTString()换成date.toUTCString()
举报