如何检查HTML sessionStorage是否为空? [英] How to check if HTML sessionStorage is not empty?

查看:646
本文介绍了如何检查HTML sessionStorage是否为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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屋!

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