JavaScript Cookie操作
2018-07-20 来源:open-open
function setCookie(NameOfCookie, value, expiredays)
{
var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + escape(value) +
((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}
function getCookie(NameOfCookie)
{
if (document.cookie.length > 0)
{
begin = document.cookie.indexOf(NameOfCookie+"=");
if (begin != -1)
{
begin += NameOfCookie.length+1;//cookie值的初始位置
end = document.cookie.indexOf(";", begin);//结束位置
if (end == -1) end = document.cookie.length;//没有;则end为字符串结束位置
document.write(document.cookie.substring(begin, end));
return unescape(document.cookie.substring(begin, end));
}
}
return null;
}
function delCookie (NameOfCookie)
{
if (getCookie(NameOfCookie))
{
document.cookie = NameOfCookie+"="+";expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:Java UNIX时间转换代码
下一篇:Java计算时间差
最新资讯
热门推荐