Common JS Summary 1

Source: Internet
Author: User

1.cookie.js (encapsulates the basic operation of cookies)

1. Introduction of Cookie.js

<script type= "Text/javascript" src= ". /js/jquery-1.11.1.min.js "></script>
<script type= "Text/javascript" src= ". /js/jquery.cookie.js "></script>

2. Common methods

1. Add: $.cookie (' The_cookie ', ' the_value ');

Note: When a cookie is not valid for a period of time, the cookie is created by default until the user closes the browser, so it is referred to as a "session cookie".

2. Access: $.cookie (' The_cookie '); The existence of a cookie = ' the_value ' cookie does not exist = NULL

3. Delete: $.cookie (' The_cookie ', null);

4. Parameter settings: $.cookie (Cookie_name, $ ("#username"). Val (), {path: '/', expires:10, domain: ' jquery.com ', Secure:true });

Note: When a cookie is specified, the cookie created is referred to as a "persistent cookie (persistent cookie)".

Expires: (number | Date), you can set an integer as the validity period (in days), or you can set a Date object as the expiration date for the cookie. If the specified date is negative, the cookie will be deleted, and if not set or set to NULL, then this cookie will be treated as a session cookie and deleted after the browser is closed

Path: (String) A cookie that is by default the page path that created the cookie

Domain: (String) The name attribute of the cookie, which is the page domain name that created the cookie by default

Secure: (Boolean) If set to true, then the transfer of this cookie requires a security protocol such as HTTPS

2.store.js (Local storage)

1. Introduction of Store.min.js and Store+json2.min.js

<script type= "Text/javascript" src= ". /js/jquery-1.11.1.min.js "></script>
<script type= "Text/javascript" src= ". /js/store.min.js "></script>
<script type= "Text/javascript" src= ". /js/store+json2.min.js "></script>

2. Common methods

1. Set Value: Store.set ("name", "value")

Store.set ("user", {name: "Zhang San", age:32});

2. Get the value: Var value=store.get ("name");

3. Delete value: Store.remove ("name")

4. Clear the Use: Store.clear ();

3.data.js (data center + message subscription)

1. Introduction of Data.js

<script type= "Text/javascript" src= ". /js/jquery-1.11.1.min.js "></script>
<script type= "Text/javascript" src= ". /js/data.js "></script>

2. Common methods

1. Get an example: Var d=new Data (), or Var d=data ();

2. Set Value: Data.set ("name", "value")

Note: You can operate on the default datacenter or on a specific instance

3. Determine if the value exists: Data.has ("name")//return TRUE or False

4. Get the value: Data.get ("name")

5. Add subscription: Var id=data.sub (Type,key,callback)

Type {String} subscription message types (optional values: Set, add, update, delete, respectively, for settings, additions, updates, deletions, where set is a generic type, the other three is a subdivision type, and mutually exclusive)

Key value of key {String} subscription message

callback {function} message accept function

The consent ID of the return {number} message is used to unsubscribe from the event

6. Unsubscribe from Var id=data.unsub (Type,key,id (optional))

Common JS Summary 1

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.