jQuery cookie使用
什么是jquery cookie?
A simple, lightweight jQuery plugin for reading, writing and deleting cookies.
Usage
创建会话cookie:
$.cookie('name', 'value');
创建一个过期时间为7天的cookie:
$.cookie('name', 'value', { expires: 7 });
创建一个有效期的cookie,并设置它的存储路径:
$.cookie('name', 'value', { expires: 7, path: '/' });
如果不写path的话,默认会跟创建页面的路径一样.
读取cookie:
$.cookie('name'); // => "value"
$.cookie('nothing'); // => undefined
读取所有有效的cookie:
$.cookie(); // => { "name": "value" }
删除cookie:
cookie删除成功返回true,否则返回false:
$.removeCookie('name'); // => true
$.removeCookie('nothing'); // => false
删除一个带有路径的cookie:
$.cookie('name', 'value', { path: '/' });
// This won't work!
$.removeCookie('name'); // => false
// This will work!
$.removeCookie('name', { path: '/' }); // => true
Note: when deleting a cookie, you must pass the exact same path, domain and secure options that were used to set the cookie, unless you're relying on the default options that is.
Configuration
关闭cookie编码
raw
By default the cookie value is encoded/decoded when writing/reading, using encodeURIComponent/decodeURIComponent. Bypass this by setting raw to true:
$.cookie.raw = true;
json格式自动转换
json
Turn on automatic storage of JSON objects passed as the cookie value. Assumes JSON.stringify and JSON.parse:
$.cookie.json = true;
Cookie Options
Cookie attributes can be set globally by setting properties of the $.cookie.defaults object or individually for each call to $.cookie() by passing a plain object to the options argument. Per-call options override the default options.
过期时间
expires
expires: 365
Define lifetime of the cookie. Value can be a Number which will be interpreted as days from time of creation or a Date object. If omitted, the cookie becomes a session cookie.
cookie存储路径路径
path
path: '/'
Define the path where the cookie is valid. By default the path of the cookie is the path of the page where the cookie was created (standard browser behavior). If you want to make it available for instance across the entire domain use path: '/'. Default: path of page where the cookie was created.
不能这样创建
This means one cannot set a path using path: window.location.pathname in case such pathname contains a filename like so: /check.html (or at least, such cookie cannot be read correctly).
cookie可用的域名
domain
domain: 'example.com'
Define the domain where the cookie is valid. Default: domain of page where the cookie was created.
secure:true cookie需要https
secure
secure: true
If true, the cookie transmission requires a secure protocol (https). Default: false.
Converters
没有找到相应的应用场景
Provide a conversion function as optional last argument for reading, in order to change the cookie's value to a different representation on the fly.
Example for parsing a value into a number:
$.cookie('foo', '42');
$.cookie('foo', Number); // => 42
Dealing with cookies that have been encoded using escape (3rd party cookies):
$.cookie.raw = true;
$.cookie('foo', unescape);
You can pass an arbitrary conversion function.
jQuery cookie使用的更多相关文章
- jquery.cookie的使用
今天想到了要为自己的影像日记增加赞的功能,并且需要用到cookie. 记得原生的js操作cookie也不是很麻烦的,但似乎jquery更简单,不过相比原生js,需要额外引入2个文件,似乎又不是很好,但 ...
- jQuery插件 -- Cookie插件jquery.cookie.js(转)
Cookie是网站设计者放置在客户端的小文本文件.Cookie能为用户提供很多的使得,例如购物网站存储用户曾经浏览过的产品列表,或者门户网站记住用户喜欢选择浏览哪类新闻. 在用户允许的情况下,还可以存 ...
- jquery cookie的用法
http://www.cnblogs.com/qiantuwuliang/archive/2009/07/19/1526663.html jQuery cookie是个很好的cookie插件,大概的使 ...
- jquery.cookie.js && java后台代码 操作cookie实现记住当前用户输入信息代码
下载jquery.cookie.js地址看这里:http://pan.baidu.com/s/1gdCPaN5 //初始化页面时验证是否记住了密码 $(document).ready(function ...
- 【转】jquery.cookie.js的使用
Cookie是由服务器端生成,发送给User-Agent(一般是浏览器),浏览器会将Cookie的key/value保存到某个目录下的文本文件内,下次请求同一网站时就发送该Cookie给服务器(前提是 ...
- jquery.cookie.js 操作cookie实现记住密码功能的实现代码
jquery.cookie.js操作cookie实现记住密码功能,很简单很强大,喜欢的朋友可以参考下. 复制代码代码如下: //初始化页面时验证是否记住了密码 $(document).ready( ...
- jquery.cookie() 的使用(原)
jquery.cookie()是一个轻量级的cookie 插件,可以读取.写入.删除 cookie. 步奏: 1. 添加jQuery插件和jQuery.cookie插件 <script src= ...
- Jquery.cookie.js 源码和使用方法
jquery.cookie.js源码和使用方法 jQuery操作cookie的插件,大概的使用方法如下 $.cookie(‘the_cookie’); //读取Cookie值$.cookie(’the ...
- jQuery.cookie.js插件了解及使用方法
jquery.cookie.js插件实现浏览器的cookie存储,该插件是基于jquery开发,方便cookie使用. jquerycookie.js的下载地址 http://plugins.jque ...
随机推荐
- [LeetCode] Binary Tree Right Side View 二叉树的右侧视图
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nod ...
- 2016BUAA校赛决赛
A. 题意:有n个点,n-1条边,1-2-3-4-5-...-n,每条边都有权值,代表走这条边的时间,时刻0一个人在点1,问从时刻1~m,有哪些时刻这个人可能走到n点 分析:将每条边当作物品,可以选1 ...
- JavaScript模板引擎artTemplate.js——引入子模板
之前的例子都是单一结构的对象,如果遇到复杂对象结构,我们可以通过引入子模板来实现html的渲染. 依旧以之前的数据作为例子: <div id="content">< ...
- 前端小知识点---html换行被解析为空格的相关知识
这个系列主要记录一下常被忽略但又经常产生影响的知识点,纯做个记录,方便查询 html换行被解析为空格也是常说的3像素空隙的问题,根据测试不同浏览器产生的空隙大小会不一样,Chrome,Firefox, ...
- Servlet的生命周期
Servlet的生命周期 Servlet的生命周期是由tomcat服务器来控制的. 1 构造方法: 创建servlet对象的时候调用.默认情况下,第一访问servlet就会创建servlet对象只创建 ...
- C与指针(结构体指针,函数指针,数组指针,指针数组)定义与使用
类型 普通指针 指针数组(非指针类型) 数组指针 结构体指针 函数指针 二重指针 定义方式 int *p; int *p[5]; int (*p)[5]; int a[3][5]; struct{.. ...
- QPS 与 TPS 简介
QPS:Queries Per Second意思是"每秒查询率",是一台服务器每秒能够相应的查询次数,是对一个特定的查询服务器在规定时间内所处理流量多少的衡量标准. TPS是Tra ...
- Genymotion安装问题
今天安装虚拟机各种报错,网上收了各种资料,然而并不能解决问题.啥也没干整整一天总算找到解决方案解决. 解决方法︰ 删除所有以前的虚拟框适配器 转到设备管理器中,单击"操作" ...
- SmartAssembly使用失败记录
目标:将指定程序集混淆,禁止反编译 1.下载软件 www.red-gate.com 官网下载 因为不常用,所以用的14天试用版 2.前面的照着下面的教程,一直到第四步 http://www.cnblo ...
- DedeCMS flink_add Getshell漏洞 管理员CSRF漏洞
DedeCMS flink_add Getshell漏洞 管理员CSRF漏洞 1.漏洞利用 由于tpl.php中的$action,$content,$filename变量没有初始化,从而能操纵这些变量 ...