JQuery Cookie
发表:2016-07-07 19:15
作者:loeyae@gmail.com
$.extend({
'cookie':function(){
var len = arguments.length, c = arguments[0], v = arguments[1], t = arguments[2];
var cur = '';
if(len == 1){
if(typeof c == 'object'){
for (i in c){
if(typeof c[i] == 'object'){
if(c[i].length >= 2){
var exp = new Date();
exp.setTime(exp.getTime() + c[i][1]*1000);
cur = (i +'='+ escape(c[i][0]) +';expires='+ exp.toGMTString())
document.cookie = cur;
}
else{
cur = (i +'='+ escape(c[i][0]))
document.cookie = cur;
}
}
cur += (i +'='+ escape(c[i]));
document.cookie = cur;
}
}
else{
var cookieString = document.cookie;
var start = cookieString.indexOf(c + '=');
if (start == -1)
return null;
start += c.length + 1;
var end = cookieString.indexOf(';', start);
if (end == -1)
return unescape(cookieString.substring(start));
return unescape(cookieString.substring(start, end));
}
}
else if(len == 3){
var exp = new Date();
exp.setTime(exp.getTime() + t*1000);
cur = (c +'='+ escape(v) + ';expires='+ exp.toGMTString());
document.cookie = cur;
}
else if(len == 2){
cur = (c +'='+ escape(v));
document.cookie = cur;
}
else{
return document.cookie;
}
}
})