js cookie函数

admin4年前javascript552
///设置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; path=/";
    }
}


相关文章

对promise、resolve和reject的简单理解

        Promise构造函数接受一个函数作为参数,其中该参数又接受两个函数作为它自身的参数,分别是resolve和rej...

viewjs使用参考

https://www.jq22.com/jquery-info6536{eyou:static file="/public/plugins/viewerjs/css/viewer.min....

将不带www的域名301转向到带www的域名

nginx:if ( $host = "zhuoshenghuanbao.com" ) {rewrite ^/(.*)$ http://www.zhuoshenghuanbao.c...

swiper常用参数

var swiper = new Swiper(".mySwiper", {     &...

animate.css动画案例

https://animate.style/...

laydate使用

laydate.render({         elem: '#dateinput',&n...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。