下面我们来简单看看官方的示例操作:
javascript
localStorage.fresh = “vfresh.org”; //设置一个键值
var a = localStorage.fresh; //获取键值
或者使用它的API:
javascript
//清空storage
localStorage.clear();
//设置一个键值
localStorage.setItem(“fresh”,“vfresh.org”);
//获取一个键值
localStorage.getItem(“fresh”);
//return “vfresh.org” //获取指定下标的键的名称(如同Array)
localStorage.key(0);
//return “fresh” //删除一个键值
localStorage.removeItem(“fresh”);
sessionStorage相同就不用在废话了,他相当于我们的过期时间Expire=0的cookie;