cookie读写

/*
* Cookie
*/
var Cookie={
read:function(name){
var value = document.cookie.match('(?:^|;)\\s*' + name + '=([^;]*)');
return (value) ? decodeURIComponent(value[1]) : null;
},
write:function(value){
var str = value.name + '=' + encodeURIComponent(value.value);
if(value.domain){ str += '; domain=' + value.domain;}
if(value.path){ str += '; path=' + value.path;}
if(value.day){
var time = new Date();
time.setTime(time.getTime()+value.day*24*60*60*1000);
str += '; expires=' + time.toGMTString();
}
document.cookie = str;
return;
},
dispose:function(name){
var str = this.read(name);
this.write({name:name,value:str,day:-1});
return;
}
}

来源:http://p4.yokacdn.com/pic/div/2012/products/index/yokaIndex.js

原文地址:https://www.cnblogs.com/lyweb/p/cookie.html