需要来自SweetAlert的返回值以确认删除操作

时间:2017-09-11 17:34:49

标签: javascript sweetalert

我有一个删除一行的按钮

<a href="<?php echo base_url('sekertaris_controller/f1_delete/'); echo $row->kode_f1;?>" onclick="return dialog()"><button class="btn btn-danger btn-sm"><i class="fa fa-trash"></i></button></a>

并使用javascript dialog()作为触发链接

<script>
    function dialog() {
        swal({
            title: 'Are you sure?',
            text: "You won't be able to revert this!",
            type: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes, delete it!'
        }).then(function() {
            swal(
                'Deleted!',
                'Your file has been deleted.',
                'success'
            )

        });

    }
</script>

问题是SweetAlert已关闭且行中的数据已删除而未经确认

1 个答案:

答案 0 :(得分:0)

function dialog() {
    swal({
        title: 'Are you sure?',
        text: "You won't be able to revert this!",
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes, delete it!'
        cancelButtonText: 'Cancel',
        closeOnConfirm: false,
        closeOnCancel: false
    }, function (isConfirm) {
        if (isConfirm) {
            swal("Deleted!", "Your imaginary file has been deleted.", "success");
        } else {
            swal("Cancelled", "Your imaginary file is safe :)", "error");
        }
    });
}