Home > Web Front-end > HTML Tutorial > HTML study notes three (use of localstorage)_html/css_WEB-ITnose

HTML study notes three (use of localstorage)_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:43:20
Original
1243 people have browsed it

Use of localstorage

1. Get the object

var localstroage = window.localStorage;
Copy after login

2. Store the value

localstroage.setItem('openid','ksjhfkjajkdfjkszdjfksad');			localstroage.setItem('uid','10001');
Copy after login

3. Get the value

var openid = localstroage.getItem('openid');
Copy after login

4. Delete a certain value

localstroage.removeItem('openid');
Copy after login


5. Delete all values ​​

localstroage.clear();
Copy after login

6. Traverse all key values ​​

localStorage.uid = 1;localStorage.sex='nan';localStorage.age = 23;for ( var i = 0, len = localStorage.length; i < len; ++i ) {    console.log( localStorage.key( i ) +':' + localStorage.getItem(localStorage.key( i ))  );}
Copy after login

Note: 1. If you don’t actively delete localstorage, it will not Automatically cleared ones will not be cleared like cookies

2. Localstorage supports almost all browsers without considering the issue size of IE8 which is 5M


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template