Installation

Include script after the jQuery library (unless you are packaging scripts somehow else):

<script src="/path/to/jquery.cookie.js"></script>

Usage

Create session cookie:

$.cookie('the_cookie', 'the_value');

Create expiring cookie, 7 days from then:

$.cookie('the_cookie', 'the_value', { expires: 7 });

Create expiring cookie, valid across entire page:

$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' });

Read cookie:

$.cookie('the_cookie'); // => 'the_value'
$.cookie('not_existing'); // => null

Delete cookie by passing null as value:

$.cookie('the_cookie', null);

Options

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 is a session cookie.

path: '/'

Default: path of page where the cookie was created.

Define the path where 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 page use path: '/'. If you want to delete a cookie with a particular path, you need to include that path in the call.

domain: 'example.com'

Default: domain of page where the cookie was created.

secure: true

Default: false. If true, the cookie transmission requires a secure protocol (https).

raw: true

Default: false.

By default the cookie is encoded/decoded when creating/reading, using encodeURIComponent/decodeURIComponent. Turn off by setting raw: true.

官网地址:http://plugins.jquery.com/project/Cookie

API - jQuery之操作cookie(转)的更多相关文章

  1. Jquery操作cookie,实现简单的记住用户名的操作

     一.jquery.cookie.js介绍  jquery.cookie.js是一个基于jquery的插件,一个轻量级的cookie 插件,可以读取.写入.删除 cookie. jquery.cook ...

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

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

  3. 关于Jquery 操作Cookie 取值错误

    使用JQuery操作cookie时 发生取的值不正确的问题: 结果发现cookie有四个不同的属性: 名称,内容,域,路径 $.cookie('the_cookie'); // 读取 cookie $ ...

  4. jquery操作cookie {分享}

    web开发过程中如果网站有一部分信息是存储在cookie中并与服务器交互的话,那么前台有时就会遇到需要对cookie中信息进行操作的情况,一个最典型的例子就是在前台判断用户是否登录过当前所访问的网站. ...

  5. Jquery操作Cookie取值错误的解决方法

    使用JQuery操作cookie时 发生取的值不正确,结果发现cookie有四个不同的属性,分享下错误的原因及解决方法. 使用JQuery操作cookie时 发生取的值不正确的问题:  结果发现coo ...

  6. jquery.cookie 使用文档,$.cookie() 文档教程, js 操作 cookie 教程文档。

    jquery.cookie 使用文档,$.cookie() 文档教程, js 操作 cookie 教程文档. jquery.cookie中的操作: jquery.cookie.js是一个基于jquer ...

  7. 【转载】使用Jquery操作Cookie对象

    Cookies是一种能够让网站服务器把少量数据储存到客户端的硬盘或内存,或是从客户端的硬盘读取数据的一种技术.jQuery是一个封装好的JavaScript库,使用jQuery可以极大地简化了Java ...

  8. 本地使用js或jquery操作cookie在谷歌浏览器chrome中不生效

    一般是在本地调试cookie,无论使用jquery cookie插件还是js原生态cookie方法,在谷歌浏览器chrome中都不生效,这是什么原因? 原因是: chrome不支持js在本地操作coo ...

  9. jQuery 操作cookie保存用户浏览信息

    使用jQuery操作cookie之前需要引入jQuery的一个cookie小组件js,代码如下:   /*         jQuery cookie plugins */jQuery.cookie ...

随机推荐

  1. Parallel.For with await and wait()

    static void Parallel2() { ParallelLoopResult result = Parallel.For(, , i => { Log($"S:{i} &q ...

  2. MVC ---- Lambda表达式

    Lambda表达式是比匿名函数还简洁的一种匿名方法语法 Lambda表达式缩写推演 new Func<string,int>(delegate(string str){return str ...

  3. Node.js结合Selenium做Web自动化测试

    发现腾讯课堂上有个node.js结合Selenium做Web自动化测试的教学视频, 听来感觉不错,一来老师讲的还不错,二来node.js这门语言会越来越热,学会总没什么坏处,三来发现CukeTest这 ...

  4. Python day12部分内置函数的常见方法

    #内置函数 print(abs(-1))#绝对值 ']))#判断list的真假,都真则真,有一个假也是假 print(any(''))#有一个真就真,全假则假 print(bin(3))#十进制转换二 ...

  5. 使用R内置函数操作数据框

    我们已经学习了数据框的基础,这里回顾一下用于筛选数据框的内置函数.尽管数据框本质上是一个由向量构成的列表,由于各列长度相同,所以可以将其看作矩阵进行访问和操作.选择满足特定条件的行,需要为 [ ] 的 ...

  6. VcCallC#_01

    1.C# 代码: using System; using System.Collections.Generic; //using System.Linq; using System.Text; //u ...

  7. [源][osg][osgBullet]osgBullet例子介绍

    1.BasicDemo 基本样例 一个小玩具飞机坠落,一个立方体盒子在转圈 2.centerofmass 质心 3.collision 碰撞检测 这里有一个大神自己改的例子: http://blog. ...

  8. spark必知必会的基本概念

    首先我们从宏观的视角来窥视下大数据技术框架: 图1 大数据技术框架 从图1可以看出,数据源-数据收集-数据存储-资源管理,这是我们进行数据分析和处理的基本;图中的计算框架包括批处理.交互式分析和流处理 ...

  9. 用docker部署gitlab

    docker hub官网下载gitlab速度太慢,改用国内镜像+中文版 docker pull registry.cn-hangzhou.aliyuncs.com/lab99/gitlab-ce-zh ...

  10. python 函数参数介绍

    python 函数参数介绍 python 使用过程总,总会遇到 *args,**kw形式的参数,总是一头雾水,而且网上介绍的或是叫法不一,为此专门深入实践进而了解了函数参数的使用 具体请看代码 #-* ...