`
wangli9li
  • 浏览: 33694 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

jquery.cookie API

阅读更多
jquery.cookie

A simple, lightweight jQuery plugin for reading, writing and deleting cookies.

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);

Note when clearing cookies, you must pass the exact same options that were used to initially set the cookie.

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. <b>By default the path of the cookie is the path of the page where the cookie was created (standard browser behavior).</b> If you want to make it available for instance across the entire page use <code>path: '/'</code>. 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 <code>raw: true</code>.

Changelog
Development

- Source hosted at {GitHub}[https://github.com/carhartl/jquery-cookie]
- Report issues, questions, feature requests on {GitHub Issues}[https://github.com/carhartl/jquery-cookie/issues]

Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change you make.

Authors

{Klaus Hartl}[https://github.com/carhartl]
分享到:
评论

相关推荐

    jquery.cookie.js包

    在JavaScript的世界里,jQuery库以其简洁的API和强大的功能深受开发者喜爱。`jquery.cookie.js`是jQuery的一个扩展插件,它使得在Web应用中管理和操作Cookie变得更加简单。本篇文章将深入探讨`jquery.cookie.js`包...

    jquery1.4.2.js和jquery.cookie.js

    《jQuery 1.4.2与jQuery Cookie插件详解》 在Web开发中,JavaScript库jQuery因其简洁的语法和强大的功能而备受青睐。本篇将深入探讨jQuery 1.4.2版本及其与jQuery Cookie插件的使用,帮助开发者更好地理解和应用这...

    jquery.js和jquery.cookie.js

    **jQuery和jQuery Cookie插件详解** 在Web开发领域,jQuery是一个非常重要的JavaScript库,它极大地简化了DOM操作、事件处理、动画制作以及Ajax交互。jQuery.js是这个库的核心文件,包含了许多实用的功能,使得...

    一天弹一次jquery.cookie插件.zip

    标签"JS特效-其它代码"表明这个插件可能涉及到一些JavaScript实现的特殊效果,比如弹窗的动画展示和关闭,这些可以通过jQuery的动画API实现。 综上所述,这个压缩包中的内容涉及到了jQuery、jQuery插件开发、...

    简单的jquery.cookie插件使弹窗点击关闭后一天弹一次.zip

    `jquery.cookie` 提供了简单的 API 来创建、读取和删除 cookies。 要使用 `jquery.cookie`,你需要先引入 jQuery 和 `jquery.cookie.js` 文件。确保在 HTML 文档的 `&lt;head&gt;` 标签中加入以下代码: ```html ...

    jQuery.cookie.js下载

    当你在网页上使用`jQuery.cookie.js`时,你可以方便地创建、读取、更新和删除cookies,而不必直接处理复杂的JavaScript原生API。 以下是一些关于`jQuery.cookie.js`的关键知识点: 1. **安装与引入**: - 将`...

    jquery.cookie.js

    jQuery.cookie.js插件则通过简洁的API,让这些操作变得简单易行。 使用jQuery.cookie.js,你可以轻松地创建、读取、更新和删除Cookie。例如,以下代码演示了如何设置一个名为"user"的Cookie,并赋予其"JohnDoe"的值...

    jquery.jsoncookie.zip

    而`jquery.jsoncookie`则是一个特定的jQuery插件,专门用于处理JSON数据与Cookie之间的交互。这篇详述将深入探讨jQuery、JSON以及JSONCookie插件的相关知识。 首先,jQuery是由John Resig于2006年创建的一个轻量级...

    jquery.cookie.js 存取cookie例子

    总的来说,`jquery.cookie.js`插件提供了简洁且易用的API,使得在JavaScript中处理Cookie变得更加简单。通过理解并熟练运用这些方法,开发者可以轻松地在客户端实现数据的持久化存储,提升网页应用的功能性和用户...

    jquery.cookie.js 以及用法 cookie读取与存储

    `jquery.cookie.js`是jQuery的一个扩展插件,为开发者提供了简单易用的API来操作Cookie。本文将详细探讨`jquery.cookie.js`的使用方法,包括如何读取和存储Cookie。 ### 1. 安装和引入 首先,你需要下载`jquery....

    jquery Cookie ,jquery.js

    jQuery库,一个广泛使用的JavaScript库,提供了方便的API来操作Cookie,使得处理Cookie变得更加简单。本文将深入探讨jQuery中的Cookie操作,并结合`jquery.js`文件的使用,帮助开发者更好地理解和应用这一功能。 ##...

    用jquery.cookie写的倒计时

    在本文中,我们将深入探讨如何使用jQuery库中的`jquery.cookie`插件来实现一个具有刷新记忆功能的倒计时器。这个技术可以帮助我们创建一个在用户刷新页面后仍能保持计时状态的计时器,从而提升用户体验。 首先,...

    jQuery.cookie.js插件实现换肤功能.docx

    该插件提供了简洁易用的API接口,使得开发者能够轻松地管理和操作cookie。 #### 三、实现步骤 ##### 1. 导入jQuery和jQuery.cookie.js插件 首先,确保项目中已引入jQuery库和jQuery.cookie.js插件。可以通过CDN...

    jquery.cookies.2.2.0.min.js.zip

    jQuery Cookies是一个轻量级的jQuery插件,它为开发者提供了方便的API来操作Cookie。我们这里将深入解析jQuery Cookies 2.2.0的最小化版本——jquery.cookies.2.2.0.min.js,并探讨其主要功能和使用方法。 一、...

    jquery-cookie(Jq取cookie必备).rar

    在JavaScript中,我们通常使用`document.cookie`对象来创建、读取和删除Cookie,但其API相对复杂,而jQuery Cookie插件则为我们提供了更为简洁的接口。 接下来,我们将深入探讨jQuery Cookie的使用。这个压缩包包含...

    jQuery.cookie.js使用方法及相关参数解释

    通过以上介绍,可以看到,jQuery.cookie.js为我们提供了强大的cookie管理功能,从基本的cookie操作到复杂的参数设置,都可以通过简洁的API来实现。在实际开发中,开发者可以根据自己的需求灵活使用这些功能,以实现...

    jquery下的cookie.js文件

    但由于其原始API限制较多,如不支持跨域、最大长度限制等,jQuery.cookie.js进行了封装,解决了这些问题。它使用正则表达式解析和构建Cookie字符串,同时提供了一套完整的API来简化操作。 总结,jQuery.cookie.js是...

Global site tag (gtag.js) - Google Analytics