localStorage

localStorage,本地存储,5M,IE8+以及较新版本的主流浏览器都支持,window对象的属性

用法示例:

localStorage.a="a";

localStorage["a"]="a";

localStorage.setItem("a", "a");

var a=localStorage.a;

var a=localStorage["a"];

var a=localStorage.getItem("a");

localStorage.removeItem("a");

localStorage.clear();

for(var i=0; i<localStorage.length; i++){

  console.log(localStorage.key(i) + ":" + localStorage.getItem(localStorage.key(i)));

}

localStorage事件,浏览器支持较少。

同json数据的联合使用示例:

var type={

"html":"a","css":"margin","js":"alert"

}

localStorage.setItem("type", JSON.stringify(type));

var aaa=JSON.prase(localStorage.getItem("type"));

posted @ 2013-09-20 23:36  charling  阅读(306)  评论(0编辑  收藏  举报