localstroage用法

注意:localStorage只能存储字符串格式,几乎支持大部分浏览器 不用考虑IE8 的问题 大小为 5M

存储

localstroage.setItem(‘openid’,‘ksjhfkjajkdfjkszdjfksad’);

获取

var openid = localstroage.getItem(‘openid’);

删除某个值

localstroage.removeItem(‘openid’);

删除所有值

localstroage.clear();

遍历所有键值

 	localStorage.id = 1;
    localStorage.sex='man';
    localStorage.age = 23;
    for ( var i = 0; i < localStorage.length; ++i ) {
        console.log( localStorage.key( i ) +':' + localStorage.getItem(localStorage.key( i ))  );
    }

你可能感兴趣的:(Js,javascript)