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();
}
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短