sweetAlert2继续回归真实并压倒我的主要动作

时间:2015-08-03 08:57:53

标签: jquery sweetalert

我正在尝试使用sweetAlert2确认对话框覆盖默认的confirm()对话框。

然而,它继续返回并继续删除过程而不单击“确定”。

    $("a.confirm").click(function(){
        swal({   
              title: 'Are you sure?',   
              text: $(this).attr('data-message'),   
              type: 'warning',   
              showCancelButton: true,   
              confirmButtonColor: '#3085d6',   
              cancelButtonColor: '#d33',   
              confirmButtonText: 'Yes',   
              closeOnConfirm: true }, 
              function(isConfirm) { 
                if(isConfirm === true){
                    alert('it is true');
                } else {
                    return false;
                }
             });
    });

这个想法很简单。我在任何可能需要确认的链接上都有一个类,确认消息被分配给数据消息属性。

通常,它会自动跳到URL而不是等待单击“确定”按钮。

我查看了显示另一个对话框的示例,感谢用户,但在这种情况下,我只是在单击“确定”时返回true。不要显示其他对话框。

非常感谢任何提示

1 个答案:

答案 0 :(得分:0)

我认为这是您的预期行为:

$("a.confirm").click(function (e) {
    var _self = this;
    e.preventDefault();
    swal({
        title: 'Are you sure?',
        text: $(this).attr('data-message'),
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes',
        closeOnConfirm: true
    }, function (isConfirm) {    
        if (isConfirm === true) {
            _self.click();
        } 
    });
});