好东西还是要整理记录一下的,不然总是忘,忘了还要重新百度

转自:http://www.manongjc.com/detail/6-pluqgnzhtjbdzjk.html

Cookies

  定义:让网站服务器把少量数据储存到客户端的硬盘或内存,从客户端的硬盘读取数据的一种技术;

  下载与引入:jquery.cookie.js基于jquery;先引入jquery,再引入:jquery.cookie.js;下载:http://plugins.jquery.com/cookie/

<script type="text/javascript" src="js/jquery.min.js">
</script><script type="text/javascript" src="js/jquery.cookie.js"></script>

  jquery.cookie.js代码的内容并不多,可以直接拷贝一下

jQuery.cookie = function (key, value, options) {

    // key and value given, set cookie...
    if (arguments.length > 1 && (value === null || typeof value !== "object")) {
        options = jQuery.extend({}, options);

        if (value === null) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? String(value) : encodeURIComponent(String(value)),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
View Code

相关文章:

  • 2021-12-23
  • 2021-07-13
  • 2022-12-23
  • 2021-10-03
  • 2021-06-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-11
  • 2021-08-23
  • 2021-09-01
  • 2022-01-03
  • 2022-03-09
  • 2021-12-03
相关资源
相似解决方案