贴代码
var cookies = {
d: new Date(),
days: function(d){
return parseInt(d)*24*3600*1000;
},
iniCookie: function(val){//初始化Cookie操作
if(val === 'add'){
this.d.setTime(this.d.getTime()+this.days(2));//设置存活时间2表示2天
} else if(val === 'del'){
this.d.setTime(this.d.getTime()-this.days(1));//提前时间销毁cookie
}
this.d = this.d.toGMTString();
},
getCookie: function(name){//获取Cookie操作
var arr = document.cookie.split(';');
for(var x in arr){
var arr2 = arr[x].split('=');
//获得cookie值
if(arr2[0] === name){
return arr2[1];
}
// if(arr2[0] === 'left_active'){
// return arr2[1];
// }
}
},
setCookie: function(name){//设置Cookie操作
this.iniCookie('add');
document.cookie="left_active="+name+";expires="+this.d;
},
delCookie: function(name){//删除Cookie操作
this.iniCookie('del');
document.cookie="left_active="+name+";expires="+this.d;
},
showCookie: function(){//显示所有Cookie操作
return document.cookie;
}
}