localstorage 和 sessionstorage的实现方法差不多,可以互相参考
/*======================
* 存储变量方法 *
=======================*/
localStorage.setItem("name","caibin");
localStorage.name = "caibin";
localStorage['name'] = "caibin";
/*======================
* 读取变量方法 *
=======================*/
localStorage.getItem("name");
localStorage.name ;
localStorage['name']
localStorage.valueOf(); //读取存储在localStorage上的所有数据
localStorage.key(0); // 读取第一条数据的变量名(键值)
/*======================
* 删除变量方法 *
=======================*/
localStorage.removeItem("name"); //删除键名为name的变量
localStorage.clear(); //清空localStorage
/*======================
* 存储JSON *
=======================*/
var data={
name:'xiecanyong',
sex:'man',
hobby:'program'
};
//存JSON
var d=JSON.stringify(data);
localStorage.setItem("data",d);
//读JSON
json=localStorage.getItem("data");
var jsonObj=JSON.parse(json);