JQuery Read Write Delete cookie specific instance

Source: Internet
Author: User
Tags time interval

The JQuery cookie is a good cookie plugin, presumably using the following methods

The code is as follows Copy Code

Example $.cookie (' name ', ' value ');

Sets the value of the cookie to set the value of the name variable to

The code is as follows Copy Code

Example $.cookie (' name ', ' value ', {expires:7, path: '/', Domain: ' jquery.com ', secure:true});

Create a new cookie including the expiration path domain name, etc.

The code is as follows Copy Code

Example $.cookie (' name ', ' value ');

New Cookie

The code is as follows Copy Code

Example $.cookie (' name ', null);

Delete a cookie

var account= $.cookie (' name ');

Take a cookie (name) value to MyVar

Cases

The code is as follows Copy Code

$.cookie (' name ', ' value '); Sets the value of the cookie to set the value of the name variable to
$.cookie (' name ', ' value ', {expires:7, path: '/', Domain: ' jquery.com ', secure:true});/create a new cookie including the expiration path domain name, etc.
$.cookie (' name ', ' value '); New Cookie
$.cookie (' name ', null); Delete a cookie
var account= $.cookie (' name ');//Take a cookie (name) value to MyVar

Example 2

The code is as follows Copy Code

<script type= "Text/javascript" >
$ (function () {
var cookie_name = ' Test_cookie ';
Set cookies by time interval
$ (' a '). EQ (0). Click (function () {
$.cookie (cookie_name, ' test ', {path: '/', expires:1});
return false;
});
Set cookies, Expiration time
$ (' a '). EQ (1). Click (function () {
var date = new Date ();
Date.settime (Date.gettime () + (1 * 24 * 60 * 60 * 1000));
$.cookie (cookie_name, ' test ', {path: '/', expires:date});
return false;
});
Get cookies
$ (' a '). EQ (2). Click (function () {
Alert ($.cookie (cookie_name));
return false;
});
Delete Cookies
$ (' a '). EQ (3). Click (function () {
$.cookie (Cookie_name, NULL, {path: '/'});
return false;
});
});
</script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.