//设置cookie
function setCookie(name,value)
{
var Days = 30;
var exp = new Date();
exp.setTime(exp.getTime() + Days2460601000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
//读取cookie
function getCookie(name)
{
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg))
return unescape(arr[2]);
else
return null;
}
//删除cookie
function delCookie(name)
{
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=getCookie(name);
console.log(cval);
if(cval!=null)
document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}
//注意在进行删除cookie操作时,请确保需要删除的cookie 其后 字符串保持一致,有path,domain,secure 需拼接上
网友评论