zoukankan      html  css  js  c++  java
  • cookie操作(jquery的cookie插件源码)

    cookie : function (key, value, options) {
                var days, time, result, decode;
    
                // A key and value were given. Set cookie.
                if (arguments.length > 1 && String(value) !== "[object Object]") {
                    // Enforce object
                    options = extend({}, options);
    
                    if (value === null || value === undefined){ options.expires = -1; }
    
                    if (typeof options.expires === 'number') {
                        days = (options.expires * 24 * 60 * 60 * 1000);
                        time = options.expires = new Date();
    
                        time.setTime(time.getTime() + days);
                    }
    
                    value = String(value);
    
                    return (document.cookie = [
                        encodeURIComponent(key), '=',
                        options.raw ? value : encodeURIComponent(value),
                        options.expires ? '; expires=' + options.expires.toUTCString() : '',
                        options.path ? '; path=' + options.path : '',
                        options.domain ? '; domain=' + options.domain : '',
                        options.secure ? '; secure' : ''
                    ].join(''));
                }
    
                // Key and possibly options given, get cookie
                options = value || {};
    
                decode = options.raw ? function (s) { return s } : decodeURIComponent;
    
                return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
            },
  • 相关阅读:
    4.4 Iterator(迭代器)
    4.6 Memento(备忘录)
    4.1 Chain of Responsibility(职责链)
    4.5 Mediator(中介者)
    4.7 Observer(观察者)
    4.8 State(状态)
    4.11 Visitor(访问者)
    4.2 Command(命令)
    3.7 Proxy(代理)
    4.10 Template Method(模板方法)
  • 原文地址:https://www.cnblogs.com/gongshunkai/p/5848503.html
Copyright © 2011-2022 走看看