当甜蜜警报关闭时如何倾听 [英] How to listen for when sweet alert closes

查看:78
本文介绍了当甜蜜警报关闭时如何倾听的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用sweetalert2,我正在尝试检测警报何时关闭。但是,DeleteUnsavedImages函数未触发。我认为将函数分配给onclose键会起作用但没有运气。

I am currently working with sweetalert2 and I am trying to detect when the alert closes. However the DeleteUnsavedImages function is not firing. I thought that assigning the function to the onclose key would work but no luck.

   swal({
       html: data,
       showCloseButton: false,
       showCancelButton: false,
       width: 800,
       showConfirmButton: false,
       onClose: DeleteUnsavedImages()
   }).then(function () {

   });


function DeleteUnsavedImages(){
    var test = "-1";
}

任何帮助将不胜感激: - )

Any help would be appreciated :-)

推荐答案

我测试了我的甜蜜警报来确认问题,你只需要传递函数名称而不用()并且函数将在 onClose swal的事件处理程序中调用。它被称为传递函数的引用,当 onClose 被触发swal时调用。

I tested with my sweet alert to confirm the issue, you just need to pass the function name without () and the function will be called inside onClose event handler of swal. Its called passing a reference of the function to call when onClose gets fired of swal.

做一点改变就像这个:

   swal({
       html: data,
       showCloseButton: false,
       showCancelButton: false,
       width: 800,
       showConfirmButton: false,
       onClose: DeleteUnsavedImages        // Removed () from here
   }).then(function () {

   });


   function DeleteUnsavedImages(){
       var test = "-1";
   }

这篇关于当甜蜜警报关闭时如何倾听的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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