var cookie={
getCookie:function(name){
var cookieArray=document.cookie.split("; ");
for(var i=0; i<cookieArray.length; i++){
var arr=cookieArray[i].split("=");
if(arr[0]==name) return unescape(arr[1]);
}
return "";
},
delCookie:function(name){
var date=new Date();
date.setTime(date.getTime()-10000);//将时间设置为过去的一个时间即可删除其相关值
var cval=this.getCookie(name);
if(cval&&cval!=null)
document.cookie=name+"="+cval+";expires="+date.toGMTString();
},
addCookie:function(objName, objValue, objDay){
var str=objName+'='+escape(objValue);
if(objDay>0){
var date=new Date();
var ms=objDay*24*3600*1000;
date.setTime(date.getTime()+ms);
str+="; expires="+date.toGMTString();
}
document.cookie=str;
}
}
cookie的添加、获取以及删除
最新推荐文章于 2023-04-13 11:31:51 发布