我一直在玩 SweetAlert 插件:Sweet alert
我想制作一个删除按钮,在实际删除之前用户会收到提示。当用户再次按下“删除”时,系统会说“完成”并且用户必须再次单击“确定”才能使提示永久消失。
SweetAlert 具有计时器功能,因此您可以在几秒左右后自动关闭最后一个“完成”提示,效果很好。它们还有一个功能,您可以在其中实现当用户在“完成”提示上单击“确定”时运行的功能。问题是,如果在计时器完成后提示自动关闭,则该功能不会运行。
知道如何做到这一点吗?
使用 timer
且函数未运行:
swal({
title: "Deleted!",
text: "Your row has been deleted.",
type: "success",
timer: 3000
},
function () {
location.reload(true);
tr.hide();
});
没有timer
,但有工作功能(当点击“ok”按钮时):
swal("Deleted!", "Your row has been deleted.", "success"), function () {
location.reload();
tr.hide();
};
最佳答案
解释
我认为您必须将 swal
从函数中分离出来。我的意思是显示 swal
,函数在后台运行,模式自动关闭。
Javascript/jQuery:
swal({
title: "Deleted!",
text: "Your row has been deleted.",
type: "success",
timer: 3000
});
function () {
location.reload(true);
tr.hide();
};
带有 SweetAlert 示例的代码:
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel plx!",
closeOnConfirm: false,
closeOnCancel: false
},
function (isConfirm) {
if (isConfirm) {
swal({
title: "Deleted!",
text: "Your row has been deleted.",
type: "success",
timer: 3000
});
function () {
location.reload(true);
tr.hide();
};
}
else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
});
关于javascript - Sweet alert timer - 完成功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29945646/