甜蜜警报计时器 – 完成function

我一直在玩SweetAlert插件: Sweet alert

我想创建一个删除按钮,在实际删除之前用户会收到提示。 当用户再次按下“删除”时,则表示“已完成”并且用户必须再次单击“确定”才能提示离开。

SweetAlert具有计时器function,因此您可以在几秒钟左右后自动关闭最后一个“完成”提示,这样就可以了。 它们还有一个function,您可以在用户在“完成”提示下单击“确定”时实现要运行的function。 问题是,如果在计时器完成后提示自动关闭,则不运行该function。

有什么想法可以做到这一点?

没有运行Timer和function:

swal({ title: "Deleted!", text: "Your row has been deleted.", type: "success", timer: 3000 }, function () { location.reload(true); tr.hide(); }); 

没有计时器,但具有工作function(点击“确定”按钮):

 swal("Deleted!", "Your row has been deleted.", "success"), function () { location.reload(); tr.hide(); }; 

说明

我认为你必须将swal与function分开。 我的意思是显示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"); } }); 

我找到了解决方案

目前我正在使用sweetAlert进行实验,我为您的问题找到了解决方案。
这是我创建sweetalert的自定义函数,它将在几秒计时器后关闭。

 var sweetAlert = function(title, message, status, timer = 5000, isReload = false){ swal({ title : title, text : message + '
This pop up will close automatically in ' + timer/1000 + ' seconds...', type : status, html : true, timer : timer, allowEscapeKey : false }, function () { swal.close(); if(isReload) location.reload(true); }); var e = $(".sweet-alert").find(".swal-timer-count"); var n = +e.text(); setInterval(function(){ n > 1 && e.text (--n); }, 1000); }

您可以使用此代码调用此方法
请记住,计时器正在使用毫秒级。

 sweetAlert('Congratulation!', 'You successfully copy paste this code', 'success', 3000, false); 

Sweetalert 2的新版本解决了这个问题

https://limonte.github.io/sweetalert2/

看看普兰克

Plunker

 .