码迷,mamicode.com
首页 > Web开发 > 详细

js操作cookie的函数

时间:2014-05-09 16:38:32      阅读:332      评论:0      收藏:0      [点我收藏+]

标签:c   get   string   set   cti   a   


///设置cookie
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());
}
///获取cookie值
function getCookie(NameOfCookie) {
if (document.cookie.length > 0) {
begin = document.cookie.indexOf(NameOfCookie + "=");
if (begin != -1) {
begin += NameOfCookie.length + 1;
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end));
}
}
return null;
}
///删除cookie
function delCookie(NameOfCookie) {
if (getCookie(NameOfCookie)) {
document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}

js操作cookie的函数,布布扣,bubuko.com

js操作cookie的函数

标签:c   get   string   set   cti   a   

原文地址:http://www.cnblogs.com/afuge/p/3708755.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!