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