jquery is also capable of manipulating cookies by 1. First download the jquery.js and jquery.cookie.js two files
2. Install (actually reference)
<!--introduction of jquery-->
<script type= "Text/javascript" src= "Jquery-2.1.1.min.js" ></script>
<!--introduction of Jquery-->
<script type= "Text/javascript"
$.cookie (' name ', ' 123456789 '); //Set name=123456789 cookie
3. Common methods 3.1. Create a new cookie
$.cookie (' name ', ' value ');
You can use it directly.
do not need any more
$ (document). Ready (function () {
$.cookie (' name ', ' value ');
});
3.1.1. Setting the cookie expiration Date:
$.cookie (' name ', ' value ', {expires:7});//valid for 7 days
3.1.2. Setting the path and validity period:
$.cookie (' name ', ' value ', {expires:7,path: '/');//valid for 7 days, path is/
3.2. Read the cookie 3.2.1. Read a single cookie
$.cookie (' name ');//= + "value", already assigned cookie
$.cookie (' nothing '); = = Undefined, access to non-existent cookies
3.2.2. Read All Cookies
$.cookie ();//Gets an array {"name": "Value"}
3.3. Delete Cookie 3.3.1. Delete the cookie by name, the success will return true, otherwise false
$.removecookie (' name ');
3.3.2. If you use a cookie with the same name, you need to add a path to delete it correctly
$.cookie (' name ', ' value ', {path: '/'});
$.removecookie (' name ');//Not valid
$.removecookie (' name ', {path: '/'});//This is the right one.
For more information, refer to: Https://github.com/carhartl/jquery-cookie#readme
Native JavaScript can also achieve the above functions, just a little bit of trouble
New Cookie:
document.cookie= "Name=value";
Read cookies:
var cookies = document.cookie;
Interested friends can view: http://www.cnblogs.com/Darren_code/archive/2011/11/24/Cookie.html (Thanks to this friend's share)
jquery Manipulating cookies (native JavaScript processing cookies)