如何使用 jQuery 永久关闭 div

How to close a div permanently using jQuery

我有 5 个页面,我在第 1 页包含一个横幅,如果用户在第 1 页关闭横幅,那么横幅也不应该出现在其他页面中。

$(document).ready(function(){

      $(".alert-banner-hide").on("click", function(){
            $("#alert-banner-container").hide();
      });

});

你能帮我解决这个问题吗?提前致谢。

使用 sessionStorage 对象来获得有状态的东西:

对于关闭横幅事件:

  $(".alert-banner-hide").on("click", function(){
        $("#alert-banner-container").hide();
        sessionStorage.setItem("banner-closed","yes"); //add this instruction
  });

页面加载/文档准备就绪:

  // Copy/Paste the whole code below & don't worry 
  $(function(){
         if (sessionStorage.getItem('banner-closed')==="yes"){
              //trigger close banner
             $("#alert-banner-container").hide();
         }
    })