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

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

WBOY
WBOYOriginal
2016-06-24 11:43:201203browse

Use of localstorage

1. Get the object

var localstroage = window.localStorage;

2. Store the value

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

3. Get the value

var openid = localstroage.getItem('openid');

4. Delete a certain value

localstroage.removeItem('openid');


5. Delete all values ​​

localstroage.clear();

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 ))  );}

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


Statement:
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