function setCookie(name,value,expires,path,domain){
//设置过期时间
var oDate = new Date();
oDate.setDate(oDate.getDate()+expires);
var str = name +'='+encodeURIComponent(value)+';expires'+oDate;
//指定路径
path = path ||'/';
str+= ';path=' + path;
//设置域名
if(domain){
str += ';domain='+domain;
}
document.cookie = str;
}
//设置cookie
function getCookie(name){
//通过; 切割所有的cookie
var aCookie=document.cookie.split('; ');
//遍历cookie通过 = 切割每个cookie
for(var i=0;i<aCookie.length;i++){
var temp = aCookie[i].split('=');
//判断每个cookie的名字是否是需要的名字
if(temp[0]===name){
return decodeURIComponent(temp[1]);
}
}
}
//读取cookie
删除cookie
function removeCookie(name,path){
path = path||'/';
document.cookie = name + '=;expires=-1' + ';path=' +path;
}