Jquery sweetAlert2不断返回true并覆盖我的主要操作

Jquery sweetAlert2不断返回true并覆盖我的主要操作,jquery,sweetalert,Jquery,Sweetalert,我试图用sweetAlert2确认对话框覆盖默认的confirm()对话框 但是,它会继续返回并继续执行删除过程,而不单击“确定” $("a.confirm").click(function(){ swal({ title: 'Are you sure?', text: $(this).attr('data-message'), type: 'warning',

我试图用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,而不是等待单击OK按钮

我已经查看了一些示例,这些示例显示了一个额外的对话框,向用户表示感谢,但在本例中,我试图仅在单击“确定”时返回true。不显示其他对话框


非常感谢任何提示

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

$("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();
        } 
    });
});

这个插件不是模态的,它不等待响应。我不确定您对
return false的期望是什么?如果您想防止链接单击的默认行为,那么无论如何您必须在handler中设置它,而不是包装插件匿名函数。此解决方案非常接近,我最终捕获了href属性并将window.location设置为返回true的链接