美文网首页
cookie插件

cookie插件

作者: leleo | 来源:发表于2019-08-21 23:31 被阅读0次
    /*! jquery.cookie v1.4.1 | MIT */
    jQuery.cookie = function (name, value, options) {
      if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
          value = '';
          options = $.extend({}, options);
          options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
          var date;
          if (typeof options.expires == 'number') {
            date = new Date();
            date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
          } else {
            date = options.expires;
          }
          expires = '; expires=' + date.toUTCString();
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
      } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
          var cookies = document.cookie.split(';');
          for (var i = 0; i < cookies.length; i++) {
            var cookie = jQuery.trim(cookies[i]);
            if (cookie.substring(0, name.length + 1) == (name + '=')) {
              cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
              break;
            }
          }
        }
        return cookieValue;
      }
    };
    

    相关文章

      网友评论

          本文标题:cookie插件

          本文链接:https://www.haomeiwen.com/subject/emqmsctx.html