一段封装jscookies的简单的代码

来源:luqidong 发布时间:2013-08-12 19:42:23 点击数:
var cookie={
 
setCookie:function  (name, value, iDay) {
var oDate = new Date();
oDate.setDate(oDate.getDate()+iDay);
document.cookie = name+'='+value+';expires='+oDate;
},
getCookie:function  (name) {
var arr = document.cookie.split('; ');
for (var i = arr.length - 1; i >= 0; i--) {
var arr2 = arr[i].split('=');
if(arr2[0]===name){
return arr2[1];
}
}
return '';
},
removeCookie:function  (name) {
cookie.setCookie(name,1,-1);
}
};