JS 新增Cookie 取cookie值 删除cookie 举例详解
cookie很实用的一个功能,可以判断某个状态,在项目中使用率极高
functionsetCookie(name,value)
{
varDays=30;
varexp=newDate();
exp.setTime(exp.getTime()+Days*24*60*60*1000);
document.cookie=name+"="+escape(value)+";expires="+exp.toGMTString();
varstrsec=getsec(time);
varexp=newDate();
exp.setTime(exp.getTime()+strsec*1);
document.cookie=name+"="+escape(value)+";expires="+exp.toGMTString();
}
//读取cookies
functiongetCookie(name)
{
vararr,reg=newRegExp("(^|)"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg))
return(unescape(arr[2]));
else
returnnull;
}
//删除cookies
functiondelCookie(name)
{
varexp=newDate();
exp.setTime(exp.getTime()-1);
varcval=getCookie(name);
if(cval!=null)
document.cookie=name+"="+cval+";expires="+exp.toGMTString();
}
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短