您的位置:首页 > 其它

SweetAlert如何实现点击Confirm之后自动关闭

2017-09-13 10:00 387 查看
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() 就可以关闭
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐