美文网首页
localStorage

localStorage

作者: wuxuan94 | 来源:发表于2017-11-06 18:40 被阅读0次

1.浏览器通过localStorage对用户操作记录

var storage=window.localStorage;
//写入a字段
storage["a"]=1;
//写入b字段
storage.a=1;
//写入c字段
storage.setItem("c",3);
console.log(typeof storage["a"]);
console.log(typeof storage["b"]);
console.log(typeof storage["c"]);
//第一种方法读取
var a=storage.a;
console.log(a);
//第二种方法读取
var b=storage["b"];
console.log(b);
//第三种方法读取
var c=storage.getItem("c");
console.log(c);

2.删除localStorage

var storage=window.localStorage;
storage.a=1;
storage.setItem("c",3);
console.log(storage);
storage.clear();
console.log(storage);
=================
storage.a=1;
storage.setItem("c",3);
console.log(storage);
storage.removeItem("a");
console.log(storage.a);

3.localStorage只支持string类型

相关文章

网友评论

      本文标题:localStorage

      本文链接:https://www.haomeiwen.com/subject/vyzlmxtx.html