如何将localstorage项设置回null。 [英] How to set localstorage item back to null.

查看:446
本文介绍了如何将localstorage项设置回null。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用系统在用户发生重大更新时向用户发出警报,并且我使用LocalStorage执行此操作,当我制作系统时,我让系统检查tip是否为null,然后将当他们收到警报时提示为真。现在,我想将'tip'localstorage设置为null,并使用tip2代替。



我会这么做吗? localStorage.setItem('tip','null');

解决方案

localStorage.removeItem('tip ')如果您打算删除密钥



localStorage.setItem('tip','null') 如果您只是想将其设置为字符串null


I'm using a system to alert users when a major update has happened to a site, and I do it with LocalStorage, when I made the system, I made the system check if tip was "null", then set "tip" to true when they got the alert. Now, I would like to set the 'tip' localstorage back to null, and use "tip2" instead.

Would I do this? localStorage.setItem('tip', 'null');

解决方案

localStorage.removeItem('tip') if you are aiming to remove the key

localStorage.setItem('tip', 'null') if you just want to set it to the string "null"

这篇关于如何将localstorage项设置回null。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆