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

sweetAlert2 keeps returning true and overriding my main action

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

但是它会继续 return 并继续删除过程,而无需单击“确定”。

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

这个想法很简单。我在任何可能需要确认的 link 上有一个 class,用于确认的消息已分配给数据消息属性。

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

我查看了显示额外对话框的示例,向用户表示感谢,但在这种情况下,我只是尝试仅在单击“确定”时 return 为真。不显示附加对话框。

非常感谢任何提示

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

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