Use Web Storage to simulate databases and webstorage

Source: Internet
Author: User

Use Web Storage to simulate databases and webstorage

Body

JavaScript

There are two functions in the JavaScript script: saveStorage () and findStorage ().

 

SaveStorage () function Process

1. retrieve data from input text boxes

2. Create an object and save the obtained data as the object property.

3. Convert the object to text data in JSON format

4. Save text data in localStorage

To save data in an Object, use the new Object statement to create an Object, save the data in each attribute of the Object, and then convert the Object to text data in JSON format, use the stringify method of the json object,

Var str = JSON. tringify (data );

This method only accepts one parameter data, which indicates the object to be converted to text data in JSON format. The function of this method is to convert the object to text data in JSON format and return it.

 

FindStorage () function Process

1. Use the retrieved name as the key value in localStorage to obtain the corresponding data

2. Convert the obtained data to a JSON object

3. Obtain the attribute values of the JSON object and create the content to be output.

4. output the content to be output on the page

The key to this function is to use the parse method of the json object to convert the data obtained from localStorage to a JSON object. The usage of this function is as follows:

Var data = JSON. parse (str );

This method only accepts one str parameter, which indicates the data obtained from localStorage. The function of this method is to convert the incoming data into a JSON object and return it.

 

 

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.