在屏幕上显示SweetAlert时停止控件 [英] Stop the control while SweetAlert is on screen

查看:152
本文介绍了在屏幕上显示SweetAlert时停止控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 sweetalert2 库在我的代码中显示警报.

I am using sweetalert2 library for showing alert in my code.

ConfirmationMessage = function(msg) {
    swal({
            title: "",
            text: msg,
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Ok",
            cancelButtonText: "Cancel",
            closeOnConfirm: false,
            closeOnCancel: false,
            allowEscapeKey: true

        });
}

这是JS函数,我在其他地方使用它.

This is the JS function and I am using it at other place.

if (!ConfirmationMessage("message to show.")) {
    alert("if");           
}
else {
    alert("else");
}

我的问题是

我想在屏幕上显示警报时停止控制,并想确定是否按确定进入如果条件如果取消 strong>达到其他条件,但控件不会等待sweetalert2中的响应.

I want to stop the control when the alert is on screen and want to decide on the button push if OK come to If Condition if Cancel come to else condition but control does not wait for the response in sweetalert2.

推荐答案

创建swal如果您查看 docs ,您会发现swal返回了承诺,因此您可以利用它并传递成功和失败回调:

If you look at the docs, you can see that swal returns a promise, so you can take advantage of that and pass the success and fail callbacks:

ConfirmationMessage = function(msg) {
  return swal({ ... }); // <--- return the swal call which returns a promise
};

ConfirmationMessage('message to show')
  .then(function() {
    // success happened
  }, function(dismiss) {
    // fail happened
    // dismiss can be 'cancel', 'overlay', 'close', and 'timer'
    if (dismiss === 'cancel') {
      // user cancelled
    }
  });

这篇关于在屏幕上显示SweetAlert时停止控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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