使用sweetalert防止页面重新加载

时间:2016-09-02 08:32:28

标签: jquery alert sweetalert

产品移除后,我会发出甜蜜警报。但是,页面会在sweetalert的几毫秒内重新加载window.location.reload();。除非我点击确定,否则我怎么能不重新加载。就像普通的alert()一样。

swal({
    title: "Product removed from your watchlist!",
    type: "success",
    confirmButtonClass: "btn-success",
    confirmButtonText: "OK!",
    closeOnConfirm: false
});    
window.location.reload();

1 个答案:

答案 0 :(得分:2)

swal({
 title: "Product removed from your watchlist!",
 type: "success",
 confirmButtonClass: "btn-success",
 confirmButtonText: "OK!",
 closeOnConfirm: false
}, function(isConfirm){
    if (isConfirm) {     
       window.location.reload();
   } 
});    

他们在演示中给出了一个这样的例子:http://t4t5.github.io/sweetalert/ 检查一个说 - " ...并通过传递一个参数,你可以为取消"执行其他操作。