能查到证明有人指引,直接上代码
<script type="text/javascript">
function cunchu1(){
var arr = [ 1, 2, 3 ];
localStorage.setItem("temp", arr); //存入 参数: 1.调用的值 2.所要存入的数据
console.log(localStorage.getItem("temp"));//输出
}
function cunchu2(){
//JSON对象转JSON字符串
var obj = {"a": 1,"b": 2};
obj = JSON.stringify(obj); //转化为JSON字符串
localStorage.setItem("temp2", obj);
}
function qingkong(){
localStorage.clear()
}
function shanchu(){
localStorage.removeItem("temp");
}
function huoqu1(){
alert(localStorage.getItem("temp"));
}
function huoqu2(){
var oo = JSON.parse(localStorage.getItem("temp2"));
alert(oo.a);
}
</script>
运行一下,都能看懂,很low。
这两个的区别就是一个生命周期是随浏览器的,一个是保存到本地的。OK
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有