cookie的基本操作

设置,读取,删除
var odate=new Date();
odate.setDate(odate.getDate()+14);
document.cookie='user=blue;expires='+odate;
function setCookie(name,value,iDay){
var odate=new Date();
odate.setDate(odate.getDate()+iday);
document.cookie=name+'='+value+';expires='+odate;
}

function getCookie(name){
var arr=document.cookie.split('; ');
for(var i=0;i<arr.length;i++){
arr2=arr[i].split('=');
if(arr2[0]==name){
return arr2[1];
}
}
return '';
}

function removeCookie(name){
setCookie(name,1,-1);
}

posted @ 2015-04-16 17:47  focus_yaya  阅读(206)  评论(0编辑  收藏  举报