HTML5 Mobile Development Practical knowledge-local storage (2)

Source: Internet
Author: User

After understanding some basic local storage usage and ideas, let's introduce the local storage system.

Local storage is divided into three main categories: localstorage/sessionstorage/local Database

The use of Localstorage and Sessionstorage, the functions contained, the methods of invocation, etc. are all the same, and they are just different meanings. The data stored by Localstorage is long-term, and the information stored by Sessionstorage is destroyed when each session is closed (popularly speaking, the data is automatically destroyed when the page is closed).

Because of the different characteristics of the two, the application of the scene also has a very big difference. In general, when we need to store some user configuration items and other data that need to be stored for a long time, we need to use Localstorgae to save, take advantage of its aging long characteristics. Accordingly, we need to use sessionstorage when we need to implement session-based functions like shopping carts.

Since the usage of localstorage and sessionstorage is the same, we take localstorage as an example to introduce the methods of both.

1. Set the data SetItem

The usage is Localstorage.setitem ("key", "value"), which means the value is passed to key. (Sessionstorage.setitem using the same method, the following no longer described below)

2. Get Data GetItem

The usage is Localstorage.getitem ("key"), as long as the corresponding key value is entered, the corresponding value value can be extracted from it.

3. Delete specific data RemoveItem

Use Localstorage.removeitem (key) to delete the data corresponding to key.

4. Clear All data

The usage is localstorage.clear (), which means emptying data from all storage systems.

These are some of the most basic sessionstorage/localstorage usages.

HTML5 Mobile Development Practical knowledge-local storage (2)

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.