甜蜜警报计时器-完成功能 [英] Sweet alert timer - done function

查看:121
本文介绍了甜蜜警报计时器-完成功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用SweetAlert插件:甜警报

I have been playing a little with the SweetAlert plugin: Sweet alert

我想创建一个删除按钮,在实际删除之前会提示用户.当用户再次按下删除"时,然后说完成",用户必须再次单击确定",提示才能永久消失.

I wanted to make a delete button, where the user gets prompted before the actual delete. When the user then presses "delete" again, is then says "done" and the user has to click "ok" again for the prompt to go away for good.

SweetAlert具有计时器功能,因此您可以在几秒钟左右的时间后自动关闭最后一个完成"提示,效果很好.它们还具有一项功能,您可以在其中实现当用户在完成"提示上单击确定"时要运行的功能.问题是,如果计时器完成后提示自动关闭,则该功能未运行.

SweetAlert has a timer function, so you can auto close that last "Done" prompt after a few seconds or so, which works just fine. They also have a feature, where you can implement a function to be run when the user clicks "OK" on the "Done" prompt. Problem is, that function is not run, if the prompt auto closes after the timer is done.

有什么想法可以做到吗?

Any ideas how this can be done?

没有运行计时器和功能:

With Timer and function not being run:

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

没有计时器,但具有工作功能(单击确定"按钮):

Without timer, but with working function (on click "ok" button):

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

推荐答案

说明

我认为您必须将swal与该功能分开.我的意思是显示swal,该功能在后台运行,模态自动关闭.

I think you have to take the swal apart from the function. What I mean is that the swal is displayed, the function runs on the background and the modal automatically closes.

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");
        }
    });

这篇关于甜蜜警报计时器-完成功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆