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.