【问题标题】:SweetAlert2 execute function after timerSweetAlert2 定时器后执行函数
【发布时间】:2016-11-02 12:15:34
【问题描述】:

我在这里做错了什么?

swal({
    title: "Done.",
    text: "Labels Printed.",
    timer: 1000,
    type: "success",
    showConfirmButton: false

}).then(function () {

    alert('done');

});

警报没有被触发,我是否需要以某种方式捕捉“计时器”? (警报只是一个例子,我实际上是在这里清除我的表单。)

另外我如何摆脱 textLabels:1 Uncaught (in promise) 计时器错误?

我使用的是.done()

有人可以为 SweetAlert2 添加标签吗?我没有这样做的声誉。

米克

当我不想以后发生任何事情时,我需要做什么?:

swal({
    title: "Error.",
    text: "Authorisation Failed.",
    timer: 1000,
    type: "error",
    showConfirmButton: false
}).then(
    function() {}

 )

像这样?:

}).then(
        function() {},
        function() {}
       )

【问题讨论】:

    标签: jquery sweetalert sweetalert2


    【解决方案1】:

    更新(2017 年 11 月 17 日):

    v7.0.0SweetAlert2 开始,工作方式与问题发起者的预期完全一样 :)


    SweetAlert2 使用承诺。每个承诺都可以resolvedrejected,您可以这样处理:

    swal(…).then(
      function () {
        // handle resolve (confirm button)
      }, 
      function (dismiss) {
        // handle reject, dismiss can be  'cancel', 'overlay', 'close', and 'timer'
      }
    )
    

    通过计时器关闭模式被视为拒绝承诺,因此您应该像这样处理它:

    Swal.fire({
      title: 'Auto close alert!',
      text: 'I will close in 2 seconds.',
      timer: 2000
    }).then(function() {
      alert('done');
    })
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

    【讨论】:

    • 太棒了,这行得通。我发现这个例子令人困惑,没有意识到我需要 function() {}。 SweetAlert2 很棒。谢谢。
    • 很高兴为您提供帮助,感谢您使用 SweetAlert2!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多