我想知道如何检查本地存储中存储的项目的值是 true 还是 false。
这就是我所拥有的,但 if 语句不起作用。
function setCBT(){
localStorage.setItem('testObject', true);
}
function alertLocalStorage(){
var object = localStorage.getItem('testObject');
if(object == true) {
alert("This item is true");
}
else {
alert("This item is false");
}
}
最佳答案
all the implementations Safari, WebKit, Chorme, Firefox and IE, are following an old version of the WebStorage standard, where the value of the storage items can be only a string.
因此您需要将值与字符串进行比较:
if(object == "true") {
这是Alternative 发布者 CMS 。
关于javascript - 检查本地存储值是否等于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29385953/