简体   繁体   English

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

[英]Error in displaying sweet alert dialog

I'm trying to make an alert using the Sweet Alert library. 我正在尝试使用Sweet Alert库发出警报。 I have tried to integrate the code for making a confirmation alert for deleting an item, but when I click on the button for deleting the item these not work. 我试图集成代码以发出删除项目的确认警报,但是当我单击删除项目的按钮时,这些代码不起作用。 The dialog is not displayed. 该对话框不显示。

Code before integrating 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;
});

Code after integrating Sweet Alert: 整合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;

});

I think there's a syntax error in your code. 我认为您的代码中存在语法错误。 Try this, see if it works [I HAVE NOT TESTED THE CODE ON MY SIDE]. 尝试此操作,看看它是否有效[我尚未在我的侧面测试代码]。 If it does not work, let me know 如果它不起作用,请告诉我

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM