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() 就可以关闭