甜蜜警报关闭时如何收听

Hay*_*ore 3 javascript jquery sweetalert sweetalert2

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

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

   });


function DeleteUnsavedImages(){
    var test = "-1";
}
Run Code Online (Sandbox Code Playgroud)

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

Him*_*yay 6

我测试了我的甜蜜警报以确认问题,您只需要传递不带名称的函数名(),该函数将在onCloseswal的事件处理程序中调用。调用onCloseswal 时传递对函数的引用以进行调用。

进行如下更改:

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

   });


   function DeleteUnsavedImages(){
       var test = "-1";
   }
Run Code Online (Sandbox Code Playgroud)