如何在甜蜜警报关闭时收听

新手上路,请多包涵

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

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

   });

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

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

原文由 Hayden Passmore 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 323
2 个回答

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

像这样做一点改变:

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

   });

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

原文由 Himanshu Upadhyay 发布,翻译遵循 CC BY-SA 3.0 许可协议

swal({
     html: data,
     showCloseButton: false,
     showCancelButton: false,
     width: 800,
     showConfirmButton: false,
     onClose: () => {
         this.DeleteUnsavedImages();
     }
})

private DeleteUnsavedImages(){
}

原文由 Igor.V 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题