如何检查HTML sessionStorage是否为空? [英] How to check if HTML sessionStorage is not empty?
问题描述
G'day伙伴们,
我正在试图找出在HTML5中检查空storageSession的最佳方法。
I'm trying to figure out the best way to check for empty storageSession in HTML5.
我注意到有些浏览器返回null,如果你清除或没有为sessionStorage设置任何值,有些浏览器只返回空格。
I noticed that some browser returns null and some return just empty space if you clear or did not set any values to the sessionStorage.
我是尝试了以下
if (sessionStorage.getItem('value1') == "null" && sessionStorage.getItem('value2') == "null") {
但它似乎不起作用。
任何人都有更好的方法来检查sessionStorage是否为空?
Anyone got a better way to check if a sessionStorage is empty?
感谢您的帮助,谢谢你事先。
Appreciate your help on this and thank you in advance.
推荐答案
这应该有用;问题是你的引号中有 null 。
That should work; the problem is that you have null in quotes.
此外, sessionStorage.length
将为您提供存储的值的数量。
Also, sessionStorage.length
will give you the number of values stored.
这篇关于如何检查HTML sessionStorage是否为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!