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 红包祝福语简短10字
18 周六早晨祝福语简短