显示甜蜜警报对话框时出错

时间:2017-04-30 18:14:38

标签: javascript jquery sweetalert

我尝试使用Sweet Alert库发出警报。 我试图整合代码来发出删除项目的确认提醒,但是当我点击按钮删除项目时这些不起作用。该对话框不会显示。

代码之前整合Sweet Alert:

$(".delete-link").click(function() {
    var id = $(this).attr("id");
    var del_id = id;
    var parent = $(this).parent("td").parent("tr");
    if (confirm('Sure to Delete ID no = ' + del_id)) {
        $.post('delete.php', { 'del_id': del_id }, function(data) {
            parent.fadeOut('slow');
        });
    }
    return false;
});

在整合Sweet Alert之后代码

    $(".delete-link").click(function() {
        var id = $(this).attr("id");
        var del_id = id;
        var parent = $(this).parent("td").parent("tr");
    });

    swal({
            title: "Are you sure you want to delete?",
            text: "Sure to Delete ID no = " + del_id,
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Yes",
            closeOnConfirm: false
        },
        function() {
            $.post('delete.php', { 'del_id': del_id }, function(data) {
                parent.fadeOut('slow');
            });
        });
    return false;

});

1 个答案:

答案 0 :(得分:0)

我认为您的代码中存在语法错误。试试这个,看看它是否有效[我还没有测试过我的代码]。如果它不起作用,请告诉我

$(".delete-link").click(function() {
var id = $(this).attr("id");
var del_id = id;
var parent = $(this).parent("td").parent("tr");

swal({
    title: "Are you sure you want to delete?",
    text: "Sure to Delete ID no = " + del_id,
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "Yes",
    cancelButtonText: "No",
    closeOnConfirm: true,
    closeOnCancel: true
}, function(isConfirm) {
    $.post('delete.php', {'del_id':del_id}, function(data) {
        parent.fadeOut('slow');
    });
});
return false;
});