zoukankan      html  css  js  c++  java
  • jquery.cookie.js用法

    jQuery.cookie = function(d, c, a) {
        if ("undefined" != typeof c) {
            a = a || {};
            null === c && (c = "", a = $.extend({},
            a), a.expires = -1);
            a.expires || (a.expires = 1);
            var b = "";
            if (a.expires && ("number" == typeof a.expires || a.expires.toUTCString))"number" == typeof a.expires ? (b = new Date, b.setTime(b.getTime() + 864E5 * a.expires)) : b = a.expires,
            b = "; expires=" + b.toUTCString();
            var e = a.path ? "; path=" + a.path: "",
            f = a.domain ? "; domain=" + a.domain: "",
            a = a.secure ? "; secure": "";
            document.cookie = [d, "=", encodeURIComponent(c), b, e, f, a].join("")
        } else {
            c = null;
            if (document.cookie && "" != document.cookie) {
                a = document.cookie.split(";");
                for (b = 0; b < a.length; b++) if (e = jQuery.trim(a[b]), e.substring(0, d.length + 1) == d + "=") {
                    c = decodeURIComponent(e.substring(d.length + 1));
                    break
                }
            }
            return c
        }
    };

    用法:

    设置 cookie:

    $.cookie('the_cookie', 'the_value');

    注:如果 $.cookie 没有第三个参数,那么当浏览器关闭时,该 cookie 将会自动删除。

    设置一个有效期为 7 天的 cookie:

    $.cookie('the_cookie', 'the_value', {expires: 7});

    注:$.cookie 第三个参数是一个对象,除了可以设置有效期(expires: 7),还可以设置有效路径(path: '/')、有效域(domain: 'jquery.com')及安全性(secure: true)。

    读取 cookie:

    $.cookie('the_cookie');

    注:如果没有该 cookie,返回 null。

    删除 cookie:

    $.cookie('the_cookie', null);

    我们只需要给需要删除的 cookie 设置为 null,就可以删除该 cookie。

  • 相关阅读:
    mysql 表分区
    mysql 存储过程和函数
    mysql 主从复制
    nginx 生产中配置记录
    harbor资源管理垃圾回收
    harbor部署
    docker使用nfs 做跨主机存储
    基于Gluster分布式实现docker存储卷
    docker 部署elasticsearch集群
    记一次iptables配置(REJECT --reject-with icmp-host-prohibited)
  • 原文地址:https://www.cnblogs.com/hejianrong/p/5798162.html
Copyright © 2011-2022 走看看