jquery Plugin Cookie

Source: Internet
Author: User
Tags set time set cookie

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

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.