javascript - 如何在删除时添加模态

标签 javascript php jquery codeigniter

如何在删除按钮上添加模型类。

现在我得到了默认的确认对话框,但我想在 php CodeIgniter 中使用不同的模式框。

function delete_data(id, type) {
    var r = confirm("<?php echo $this->lang->line('delete_confirmation'); ?>");
    if (r == true) {
        // var type = $('#type').val();
        $.ajax({
            url: "<?php echo BASE_URL . 'admin/delete'; ?>",
            type: 'POST',
            data: 'id=' + id + '&type=' + type,
            success: function (data) {
                if (data == 1) {
                    Materialize.toast('delete_success', 'top left', 'green', "<?php echo ('deleted_successfully'); ?>");
                    //window.location='<?php echo BASE_URL; ?>'+'admin/student_list';
                    location.reload();
                } else {
                    Materialize.toast('delete_error', 'top left', 'red', "<?php echo ('delete_error'); ?>");
                }
            }
        })
    } else {
    }
}

 <a href="#" onclick="delete_data(<?php echo $row['id'];?>,'student');" class="btn-floating  red darken-2"><i class="material-icons right">close</i></a>

最佳答案

你可以试试这个。我从 Materialise 主题网站获取了代码

http://demo.geekslabs.com/materialize-v1.0/advanced-ui-sweetalert.html

并与上面的函数剪切粘贴在一起。

为什么是的,它完全未经测试。 =)

function delete_data(id, type) {

    swal({
        title: "Are you sure?",
        text: "You will not be able to recover this imaginary file!",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: '#DD6B55',
        confirmButtonText: 'Yes, delete it!',
        cancelButtonText: "No, cancel plx!",
        closeOnConfirm: false,
        closeOnCancel: false
    },
    function(isConfirm){
        if (isConfirm){
            $.ajax({
                url: "<?php echo BASE_URL . 'admin/delete'; ?>",
                type: 'POST',
                data: 'id=' + id + '&type=' + type,
                success: function (data) {
                    if (data == 1) {
                        swal("Deleted!", "Your imaginary file has been deleted!", "success");

              //  Materialize.toast('delete_success', 'top left', 'green', "<?php echo ('deleted_successfully'); ?>");
                //window.location='<?php echo BASE_URL; ?>'+'admin/student_list';
                        location.reload();
                    } else {
                        swal("Cancelled", "Your imaginary file is safe :)", "cancel");
               // Materialize.toast('delete_error', 'top left', 'red', "<?php echo ('delete_error'); ?>");
                    }
                }
            })

        } else {

            swal("Cancelled", "Your imaginary file is safe :)", "cancel");
        }
    });
});

此外,此代码来自 Materialize 主题站点,其字面意思如图所示,只是封装在 jQuery 事件监听器中。

$('.btn-warning-cancel').click(function(){
    swal({
        title: "Are you sure?",
        text: "You will not be able to recover this imaginary file!",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: '#DD6B55',
        confirmButtonText: 'Yes, delete it!',
        cancelButtonText: "No, cancel plx!",
        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");
        }
    });

});

关于javascript - 如何在删除时添加模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47010154/

相关文章:

javascript - Typescript rxjs 可观察数组连接

php - preg_match 在 anchor 上提取 mailto

php - 需要从基于子域的 Mysql 数据库中提取图像 url 列表,并将它们存储为列表

c# - 在域驱动设计中的身份和访问限界上下文中实现多个用户

javascript - JavaScript 类/字典中的对象键?

php - 折线图生成

javascript - 使用 Casperjs 清除本地存储

javascript - c9 - 如何从脚本标签运行 php 函数?

javascript - 选中复选框时如何将选择值更改为特定值

javascript - 如何记录、撰写报价?