如何在删除按钮上添加模型类。
现在我得到了默认的确认对话框,但我想在 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/