我在这里做错了什么?
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() {}
)
最佳答案
更新(2017 年 11 月 17 日):
从v7.0.0开始SweetAlert2 的工作方式与问题发起者的预期完全一样:)
<小时/>SweetAlert2 使用 Promise。每个 promise 都可以解决或拒绝,您可以这样处理:
swal(…).then(
function () {
// handle resolve (confirm button)
},
function (dismiss) {
// handle reject, dismiss can be 'cancel', 'overlay', 'close', and 'timer'
}
)
通过计时器关闭模式被视为 promise 拒绝,因此您应该像这样处理它:
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>
关于jquery - SweetAlert2 在定时器之后执行函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40379733/