1. Determine if local storage is available:
if (window.localstorage) { //Localstorge available }else { //Localstorge unavailable }
2. Store Data:
Gets the local storage object var localstorage =window.localstorage; Storage Localstorage.setitem ("key", content);
3. Remove the data
var myKey =localstorage.getitem ("key");
4. Delete the specified data
Localstorage.removeitem ("key");
5. Clear Local Data
Localstorage.clear ();
6. Storing and reading JSON data
Define the JSON variable var json ={username: "Yang Zhilai", Sex:1,age:25,birthday: "1990-08-21", Phonenumber:13812345678,disease: " Pulmonary nodules ", Insurance:1,avatar:" Images/male.png "}; JSON variable converted to JSON string var jsonstr =json.stringify (JSON); Store JSON string window.localStorage.setItem ("Jsonkey", jsonstr); Remove the JSON string var jsonstr =window.localstorage.getitem ("Jsonkey"); Restore JSON object var json =json.parse (JSONSTR); Remove the username var username =json.username inside the JSON;
JavaScript enables simple local data access and JSON data access