代码如下:

/*!
* jQuery Cookie Plugin v1.4.1
* https://github.com/carhartl/jquery-cookie
*
* Copyright 2013 Klaus Hartl
* Released under the MIT license
*/
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// CommonJS
factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {

var pluses = /\+/g;

function encode(s) {
return config.raw ? s : encodeURIComponent(s);
}

function decode(s) {
return config.raw ? s : decodeURIComponent(s);
}

function stringifyCookieValue(value) {
return encode(config.json ? JSON.stringify(value) : String(value));
}

function parseCookieValue(s) {
if (s.indexOf('"') === 0) {
// This is a quoted cookie as according to RFC2068, unescape...
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
}

try {
// Replace server-side written pluses with spaces.
// If we can't decode the cookie, ignore it, it's unusable.
// If we can't parse the cookie, ignore it, it's unusable.
s = decodeURIComponent(s.replace(pluses, ' '));
return config.json ? JSON.parse(s) : s;
} catch(e) {}
}

function read(s, converter) {
var value = config.raw ? s : parseCookieValue(s);
return $.isFunction(converter) ? converter(value) : value;
}

var config = $.cookie = function (key, value, options) {

// Write

if (value !== undefined && !$.isFunction(value)) {
options = $.extend({}, config.defaults, options);

if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setTime(+t + days * 864e+5);
}

return (document.cookie = [
encode(key), '=', stringifyCookieValue(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(''));
}

// Read

var result = key ? undefined : {};

// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all. Also prevents odd result when
// calling $.cookie().
var cookies = document.cookie ? document.cookie.split('; ') : [];

for (var i = 0, l = cookies.length; i < l; i++) {
var parts = cookies[i].split('=');
var name = decode(parts.shift());
var cookie = parts.join('=');

if (key && key === name) {
// If second argument (value) is a function it's a converter...
result = read(cookie, value);
break;
}

// Prevent storing a cookie that we couldn't decode.
if (!key && (cookie = read(cookie)) !== undefined) {
result[name] = cookie;
}
}

return result;
};

config.defaults = {};

$.removeCookie = function (key, options) {
if ($.cookie(key) === undefined) {
return false;
}

// Must not alter options, thus extending a fresh object...
$.cookie(key, '', $.extend({}, options, { expires: -1 }));
return !$.cookie(key);
};

}));

分享jquery.cookie.js的更多相关文章

  1. jQuery插件 -- Cookie插件jquery.cookie.js(转)

    Cookie是网站设计者放置在客户端的小文本文件.Cookie能为用户提供很多的使得,例如购物网站存储用户曾经浏览过的产品列表,或者门户网站记住用户喜欢选择浏览哪类新闻. 在用户允许的情况下,还可以存 ...

  2. jquery.cookie.js && java后台代码 操作cookie实现记住当前用户输入信息代码

    下载jquery.cookie.js地址看这里:http://pan.baidu.com/s/1gdCPaN5 //初始化页面时验证是否记住了密码 $(document).ready(function ...

  3. 【转】jquery.cookie.js的使用

    Cookie是由服务器端生成,发送给User-Agent(一般是浏览器),浏览器会将Cookie的key/value保存到某个目录下的文本文件内,下次请求同一网站时就发送该Cookie给服务器(前提是 ...

  4. jquery.cookie.js 操作cookie实现记住密码功能的实现代码

    jquery.cookie.js操作cookie实现记住密码功能,很简单很强大,喜欢的朋友可以参考下.   复制代码代码如下: //初始化页面时验证是否记住了密码 $(document).ready( ...

  5. Jquery.cookie.js 源码和使用方法

    jquery.cookie.js源码和使用方法 jQuery操作cookie的插件,大概的使用方法如下 $.cookie(‘the_cookie’); //读取Cookie值$.cookie(’the ...

  6. jQuery.cookie.js插件了解及使用方法

    jquery.cookie.js插件实现浏览器的cookie存储,该插件是基于jquery开发,方便cookie使用. jquerycookie.js的下载地址 http://plugins.jque ...

  7. jquery.cookie.js使用

    1.下载jquery.cookie.js 官网:http://plugins.jquery.com/cookie/ 或 http://pan.baidu.com/s/1mgynA8g 2.使用方法 $ ...

  8. 【jquery】jquery.cookie.js 的使用指南

    之前有写过一篇原生 js 的 cookie 介绍,并且最后封装成 cookie.js 具体内容点击传送门. jquery.cookie.js 是一款轻量级的 cookie 插件,可以读取,写入和删除 ...

  9. jquery.cookie.js 用法

    jquery.cookie.js 用法   一个轻量级的cookie 插件,可以读取.写入.删除 cookie. jquery.cookie.js 的配置 首先包含jQuery的库文件,在后面包含 j ...

随机推荐

  1. linux命令学习6-dpkg命令

    dpkg命令是Debian Linux系统用来安装.创建和管理软件包的实用工具. 1. 语法 dpkg (选项) (参数)2. 选项 -i:安装软件包: -r:删除软件包: -P:删除软件包的同时删除 ...

  2. S3C2440串口及其中断系统详解

    个独立异步串行I/O(SIO)端口,每个都可以是基于中断或基于DMA模式的操作.换句话说,UART可以通过产生中断或DMA请求来进行CPU和UART之间的数据传输. 字节的FIFO给发送和接收. 字节 ...

  3. STM32驱动AT24CXX系列芯片

    AT24Cxx系列EEPROM是由美国Mcrochip公司出品,1-512K位的支持I2C总线数据传送协议的串行CMOS E2PROM,可用电擦除,可编程自定时写周期(包括自动擦除时间不超过10ms, ...

  4. Swing 窗口的最小化到系统图标与还原

    2014年2月26日 13:01:47 一个上午的功夫,终于折腾好了. 上午主要是卡在监听事件的参数问题.当时脑子不好使,忘记事件是自己构造的,傻傻的测试了半天,如何传递窗口的参数 等中午解决的时候, ...

  5. 转自他人——————TLE之前,没有一个节点叫失败!!!

    我想我十八年来记忆最深刻的夜晚,大概便是在吉林大学燥热的宿舍里,穿着橘黄色的短袖,努力咽下大口大口的雪碧.那天晚上我仰躺在吉大热得几乎不能入眠的床板上,一动不动,看夏夜里打不尽的蚊子在惨白的天花板下飞 ...

  6. 后端数据库使用 Bomb方案

    不再需要阿里云进行部署: http://docs.bmob.cn/ios/faststart/index.html?menukey=fast_start&key=start_ios

  7. MySQL5.6生产库自动化安装部署

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://suifu.blog.51cto.com/9167728/1846671 自动化运 ...

  8. iOS 之 内存管理

    凡是alloc copy mutablecopy init 声明的变量,都需要通过手动的方式进行释放,realse. 如果 copy一个对象,则拥有了拷贝的对象,要负责释放. 如果 保持(retain ...

  9. vmwvare 网卡设置讲解

  10. C# winform 按钮设置左边图标

    按钮设置操作如下: 1.先设置按钮图标,再设置图标的对齐方式 2.再设置按钮字体的对齐方式. 3.最后设置排列: TextImageRelation:设置为ImageBeforeText