12

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

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

   });


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

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

4

3 回答 3

20

我用我的甜蜜警报进行了测试以确认问题,您只需要传递函数名称而不传递函数名称(),该函数将在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";
   }
于 2017-10-09T05:51:25.303 回答
1
swal({
     html: data,
     showCloseButton: false,
     showCancelButton: false,
     width: 800,
     showConfirmButton: false,
     onClose: () => {
         this.DeleteUnsavedImages();
     }
})

private DeleteUnsavedImages(){
}
于 2019-04-11T09:12:22.490 回答
0
swal({
    title: "client",
    content: html,
    buttons:
    {
        cancel: {
            text: "Close",
            visible: true,
            closeModal: true,
        },
        confirm: {
            text: "Download",
            visible: true,
            closeModal: false
        }
    },
}).then((confirm) => {
    if (confirm) {
        download();
    }
    else {
        DeleteUnsavedImages();
    }
});

function DeleteUnsavedImages(){
    var test = "-1";
}
于 2021-03-12T17:00:37.717 回答