首页 > 解决方案 > 我怎样才能让 sweet2alert 不再显示消息?

问题描述

如果我单击使用 localstorage,我一直在尝试隐藏此消息,"<span onclick='save()'>Don't Show Again</span>",但它不起作用。我怎么做?

<script type="text/javascript">
  if(localStorage.getItem("DontShow")) {
        $("#save").hide();
    }
    $(document).on("click", "#save", function() {
        localStorage.setItem("DontShow", "true");
    });

  Swal.fire({
            allowOutsideClick: false,
            allowEscapeKey: false,
            allowEnterKey: false,
            showCancelButton: true,
            icon: 'info',
            title: 'Title',
            html: '<div class="swal-left"><b>Text</b><br>Text</div>',

            confirmButtonColor: '#DD6B55',
            cancelButtonText: "Close",
            confirmButtonText: "<span onclick='save()'>Don't Show Again</span>",
            footer: '<a href>Why do I have this issue?</a>'
          });

  
</script>

标签: javascriptsweetalert2

解决方案


在 swal.fire 函数之后添加这个

.then((result) => {
  if (result.isConfirmed)
      'function that hides here'

});

推荐阅读