JQuery.cookie.js plug-in understanding and how to use

Source: Internet
Author: User
Tags set cookie

The Jquery.cookie.js plugin implements the cookie store of the browser, which is developed based on jquery and facilitates the use of cookies.

Jquerycookie.js's Http://plugins.jquery.com/project/cookie

1. Preparatory work

1) Since the plugin relies on jquery, first introduce the Jquey plugin on the page

2) Introducing jQuery.cookie.js on the page

2. How to use

Set cookies

/*         * *  Set Cookie        * *  The first parameter sets the cookie key        * * The  second parameter sets the value of the cookie        * *  Path to set cookie Paths        * *  expires sets the expiration time of the cookie if it is not set to expire when the browser is closed.         */         $.cookie ("area", "002", {path: '/', expires:10});

Read cookies

/*         * * Read        cookies*        /Console.log ($.cookie ("area"));

Delete Cookies

/*         * * Delete        Cookie        * * */        $.cookie ("area",null, {path: '/', Expires:10});

Examples Show

1 <!DOCTYPE HTML>2 <HTML>3 <Head>4     <title></title>5     <MetaCharSet= "Utf-8">6 </Head>7 <Body>8 <Scripttype= "Text/javascript"src= "Jquery.js"></Script>9 <Scripttype= "Text/javascript"src= "Jquery.cookie.js"></Script>Ten <Scripttype= "Text/javascript"> One     $(function(){ A         /* - * * Set Cookies - * * The first parameter sets the key of a cookie the * * The second parameter sets the value of a cookie - * * Path to set cookie - * * Expires sets the expiration time of the cookie if it is not set to expire when the browser is closed.  -         */ + $.cookie (" Area","002", {path:'/', Expires:Ten}); -  +         /* A * * Read cookies at         */ - Console.log ($.cookie (" Area")); -  -         /* - * * Delete cookies -         ** in         */ - $.cookie (" Area",NULL, {path:'/', Expires:Ten}); to     }); + </Script> - </Body> the </HTML>

JQuery.cookie.js plug-in understanding and how to use

Related Article

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.