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. 返回json格式数据乱码

    本文为博主原创,未经允许不得转载: 原本返回json格式数据的代码: @ResponseBody @RequestMapping(value = "getListByTime", ...

  2. input file获取选择图片的本地路径和base64路径

    input file获取选择图片的本地路径和base64路径 本地路径: myHeadFile: function (e) { // 这里是input file 的onchange事件 ] const ...

  3. git 代码冲突处理

    在使用git pull代码时,经常会碰到有冲突的情况,提示如下信息: error: Your local changes to 'c/environ.c' would be overwritten b ...

  4. 如何优化myeclipse.

    1.去除不需要加载的模块 一个系统20%的功能往往能够满足80%的需求,MyEclipse也不例外,我们在大多数时候只需要20%的系统功能,所以可以将一些不使用的 模块禁止 加载启动.通过Window ...

  5. 汇编语言调用Linux系统调用read和write

    .section .data UserMsg: .ascii "Please input the message:" LenOfUserMsg: .equ lenMsg, LenO ...

  6. Lua面向对象 --- 封装

    工程结构: Player.lua: Player = {} function Player:new() local self = {} setmetatable(self, {__index = Pl ...

  7. OpenGL入门程序三:点、线、面的绘制

    1.点: void TestPoint() { //点的大小默认为一个像素,通过下面的函数可以设置一点的大小 glPointSize(50.0f); glBegin(GL_POINTS); glVer ...

  8. Java JDK5新特性-增强for

    2017-10-31 00:02:16 格式: for(元素数据类型 变量:数组或者Collection集合) { 使用变量即可,该变量即是元素 } int arr[] = {1,2,3,4,5}; ...

  9. JQuery.Ajax()的data参数传递方式

    最近,新学c# mvc,通过ajax post方式传递数据到controller.刚开始传递参数,controller中总是为null.现记录一下,可能不全,纯粹记个学习日记. 重点在于参数的方式,代 ...

  10. nyoj38

    布线问题 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 南阳理工学院要进行用电线路改造,现在校长要求设计师设计出一种布线方式,该布线方式需要满足以下条件:1.把所有 ...