1, function.
Syntax: $.cookie (name, value, [option])
(1) Read Cookie value
$.cookie (cookiename) CookieName: The name of the cookie to read.
Example: $.cookie ("username"); Reads the value of the username stored in the cookie named.
(2) Write set cookie value:
$.cookie (Cookiename,cookievalue); CookieName: The cookie name to be set, Cookievalue represents the corresponding value.
Example: $.cookie ("username", "admin"); Write the value "admin" to a cookie named Username cookie.
$.cookie ("username", NULL); Destroying a cookie named username
(3) [option] parameter description:
Expires: A finite date, which can be an integer or a date (in days). This place should also note that if you do not set this thing, the cookie will expire after the browser is closed.
Path:cookie the path to the saved value, which is the same as creating the page path by default.
The Domin:cookie domain Name property, by default, is the same as creating a page domain name. This place should pay considerable attention to the concept of cross-domain, if you want the primary domain two domain name valid, you want to set the ". xxx.com"
Secrue: A Boolean value that indicates whether a security protocol is required when transferring cookie values.
Example:
$.cookie ("Like", $ (": radio[checked]"). Val (), { path: "/", Expiress:7 })
Instance:
A cookie is essentially a txt literal, so it can only be stored in a string, the object is usually serialized before it can be stored in a cookie, and the object is deserialized before it can be obtained.
$ (function () { if ($.cookie ("o") = = null) { var o = {name: "Zhang San", age:24}; var str = json.stringify (o); Serialize into a string and then deposit the cookie $.cookie ("O", str, { expires:7 //Set time, if left blank, the browser closes this cookie expires.) }); Alert ("Cookie is empty"); } else { var str1 = $.cookie ("o"); var O1 = Json.parse (STR1); The character is deserialized into object alert (o1.name); The name value of the deserialized object } })