zl程序教程

您现在的位置是:首页 >  前端

当前栏目

javascript操作cookie_获取与修改代码

JavaScriptCookie代码 操作 获取 修改
2023-06-13 09:14:09 时间
复制代码代码如下:

function$Cookie(){
vara=arguments.callee;
varb=a._cached;
if(a._cached){returna._cached}
if(!(thisinstanceofa)){returnnewa}
if(typeofa._cached=="undefined"){a._cached=this}
}
$Cookie.prototype.get=function(e){
vara=document.cookie.split(/\s*;\s*/);
vard=newRegExp("^(\\s*"+e+"\\s*=)");
for(varb=0;b<a.length;b++){
if(d.test(a[b])){returnunescape(a[b].substr(RegExp.$1.length))}
}
returnnull
};
$Cookie.prototype.set=function(e,f,d,a){
varb="";
if(typeofd=="number"){b=";expires="+(newDate((newDate()).getTime()+d*1000*60*60*24)).toGMTString()}
if(typeofa=="undefined"){a=""}
document.cookie=e+"="+escape(f)+b+";path=/"+(a?";domain="+a:"");
returnthis
};
$Cookie.prototype.remove=function(a){
if(this.get(a)!=null){this.set(a,"",-1)}
returnthis
};