码迷,mamicode.com
首页 > 其他好文 > 详细

cookie

时间:2016-08-22 18:01:57      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:


/*----设置cookie----*/
function setCookie(NameOfCookie, value, expiredays) {
    var ExpireDate = new Date();
    ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600));
    //ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 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; //cookie值的初始位置  
            end = document.cookie.indexOf(";", begin); //结束位置  
            if (end == -1) end = document.cookie.length; //没有;则end为字符串结束位置  
            return unescape(document.cookie.substring(begin, end));
        }
    }
    return null;
}

cookie

标签:

原文地址:http://www.cnblogs.com/lk516924/p/5796332.html

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