javascript - 为什么本地存储无法工作,即使它在页面刷新后不应打开?

标签 javascript jquery local-storage

我正在使用这个,但每次刷新和打开选项卡后cookies消息都会出现。

 $(document).ready(function () {
    if (!!localStorage.getItem('firstVisitVisp')) {

        localStorage.setItem('firstVisitVisp', 'true');

        setTimeout(function () {
            $("#cookieConsent").fadeIn(200);
        }, 4000);

        $("#closeCookieConsent, .cookieConsentOK").click(function () {
            $("#cookieConsent").fadeOut(200);
        });
    }
});

最佳答案

你就快到了 - 只需删除 !! 并将其更改为 !:

if (!localStorage.getItem('firstVisitVisp')) {...}

关于javascript - 为什么本地存储无法工作,即使它在页面刷新后不应打开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55557159/

相关文章:

javascript - ES6 类和同步执行

ios - 覆盖后文档目录中的图像没有变化

javascript - Chrome 扩展程序和 .click() 使用 localStorage 中的值循环

javascript - jQuery 中的 Tablesorter 和多文本提取?

jquery - 边框斜 Angular 透明仅使用 css

jquery 按子元素的大小对 ul 元素进行排序

javascript - JQuery - 使用 .html() 设置后获取 .html()

javascript - 从所有数组项中切片字符

javascript - CSS 图像右对齐 - Firefox 6.02 中的额外行

javascript - 更改状态栏中的链接