[JavaScript] 自定义jQuery操作Cookie的类 →→→→→进入此内容的聊天室

来自 , 2019-05-28, 写在 JavaScript, 查看 146 次.
URL http://www.code666.cn/view/be341249
  1. jQuery.cookie = function(name, value, options) {
  2.           if (typeof value != 'undefined') {
  3.                     options = options || {};
  4.                     if (value === null) {
  5.                               value = '';
  6.                               options = $.extend({}, options);
  7.                               options.expires = -1;
  8.                     }
  9.                     var expires = '';
  10.                     if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
  11.                               var date;
  12.                               if (typeof options.expires == 'number') {
  13.                                         date = new Date();
  14.                                         date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
  15.                               } else {
  16.                                         date = options.expires;
  17.                               }
  18.                               expires = '; expires=' + date.toUTCString();
  19.                     }
  20.                     var path = options.path ? '; path=' + (options.path) : '';
  21.                     var domain = options.domain ? '; domain=' + (options.domain) : '';
  22.                     var secure = options.secure ? '; secure' : '';
  23.                     document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
  24.           } else {
  25.                     var cookieValue = null;
  26.                     if (document.cookie && document.cookie != '') {
  27.                               var cookies = document.cookie.split(';');
  28.                               for (var i = 0; i < cookies.length; i++) {
  29.                                         var cookie = jQuery.trim(cookies[i]);
  30.                                         if (cookie.substring(0, name.length + 1) == (name + '=')) {
  31.                                                   cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  32.                                                   break;
  33.                                         }
  34.                               }
  35.                     }
  36.                     return cookieValue;
  37.           }
  38. };
  39.  
  40.  
  41.  
  42. //javascript/7081

回复 "自定义jQuery操作Cookie的类"

这儿你可以回复上面这条便签

captcha