PHP 应用程序上的甜蜜警报确认删除无法正常工作
Sweet alert confirm delete on PHP app is not working
在我的 PHP 应用程序中,单击 link/button
通常会删除它
但是当我实施 sweet alert 时它不起作用或者只是 return 错误。我正在使用 sweetalert2
这是我的按钮代码
<a href="http://localhost/app/pages-role-list.php?delete_role=18" class="btn btn-sm btn-danger delete-confirm">delete</a>
我亲爱的初始化
$('.delete-confirm').on('click', function (event) {
event.preventDefault();
const url = $(this).attr('href');
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'question',
showCancelButton: true,
confirmButtonText: 'Delete'
},function(isConfirm){
if (isConfirm) {
return true;
window.location.href = url;
}else{
return false;
}
})
});
回调没有使用正确的语法..
这是工作代码:
$('.delete-confirm').on('click', function (event) {
event.preventDefault();
const url = $(this).attr('href');
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'question',
showCancelButton: true,
confirmButtonText: 'Delete'
}).then((result) => {
if (result.value) {
window.location.href = url;
} else if (result.dismiss === Swal.DismissReason.cancel) {
event.preventDefault();
}
})
});
在我的 PHP 应用程序中,单击 link/button
通常会删除它但是当我实施 sweet alert 时它不起作用或者只是 return 错误。我正在使用 sweetalert2
这是我的按钮代码
<a href="http://localhost/app/pages-role-list.php?delete_role=18" class="btn btn-sm btn-danger delete-confirm">delete</a>
我亲爱的初始化
$('.delete-confirm').on('click', function (event) {
event.preventDefault();
const url = $(this).attr('href');
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'question',
showCancelButton: true,
confirmButtonText: 'Delete'
},function(isConfirm){
if (isConfirm) {
return true;
window.location.href = url;
}else{
return false;
}
})
});
回调没有使用正确的语法..
这是工作代码:
$('.delete-confirm').on('click', function (event) {
event.preventDefault();
const url = $(this).attr('href');
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'question',
showCancelButton: true,
confirmButtonText: 'Delete'
}).then((result) => {
if (result.value) {
window.location.href = url;
} else if (result.dismiss === Swal.DismissReason.cancel) {
event.preventDefault();
}
})
});