javascript - 防止 SweetAlert2 从 willClose 中关闭/解除?

标签 javascript dialog sweetalert2

抱歉,如果我在文档中遗漏了一些内容,但无论如何我都找不到阻止在 SweetAlert 2 中关闭对话框的方法,这些将不起作用:

        await Swal.fire({
            html: diagHtml,
            showCancelButton: true,

            willClose: (el) => {
                console.log(el);

                if (someLogic()) {
                    event.preventDefault();
                    return false;
                }
            },
        });

有没有办法让对话框保持不变,最好使用 async

最佳答案

不,您不能使用 willClose 阻止对话框关闭,也许以下代码可以替代您:

await Swal.fire({
  html: diagHtml,
  showDenyButton: true,
  allowOutsideClick: false,
  allowEscapeKey: false,
  preConfirm: () => {
    if (someLogic()) {
      return false; // Prevent confirmed
    }
  },
  preDeny: () => {
    if (someLogic()) {
      return false; // Prevent denied
    }
  },
});

关于javascript - 防止 SweetAlert2 从 willClose 中关闭/解除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64620928/

相关文章:

javascript - Nodejs - 让客户端套接字在 5 秒超时后重试

javascript - 试图找出一些js代码中的 'this'

javascript - jQuery 移动 : How to make dialog open more than once

javascript - 如何修复 SweetAlert2 中奇怪的成功和错误图标?

c# - 使用C#模拟确认javascript弹出窗口

javascript - 如何在导航栏功能中简化 jQuery?

java - 从 DialogFragment 调用 FileProvider 时出错 - 引用对象为空,

jquery - 如何取消 jQuery UI 对话框的打开?

javascript - SweetAlert2 检测单选按钮选择

javascript - sweetalert JS 插件迁移到 Sweetalert2