swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel plx!",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm){
if (isConfirm) {
swal({
title: "Auto close alert!",
text: "I will close in 2 seconds.",
timer: 0,
showConfirmButton: false
});
alert('asd');
} else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
});
像這段代碼,可以實現點擊Confirm彈出一個新的SweetAlert框,原來的框會自動關閉,但是當我把function中的代碼改成alert('hello')之后,沒有調用swal方法,那么雖然alert可以正常執行,但是原來的框就不能自動關閉了。所以想請問下有沒有什么方法可以在回調函數中使用自定義方法,但是又能夠自動關閉原來的swal彈框。卡很久了,望大家賜教。
執行swal.close() 就可以關閉