SweetAlert isConfirm 无法正常工作
SweetAlert isConfirm does not work properly
我想在提交表单后向用户显示 Sweet Alert 2 确认消息,如下所示:
<form id="myForm" data-flag="0" action="" method="POST">
@csrf
<input type="checkbox" id="btn-submit" name="wallet_checked" onchange="this.form.submit();">
</form>
如您所见,我使用 onchange="this.form.submit();"
提交了表单,但没有使用提交按钮,而且效果很好。
然后我尝试将其添加为向用户显示 SweetAlert 消息的脚本:
$(document).on('click', '#btn-submit', function(e) {
e.preventDefault();
let form = $(this).parents('form');
swal(
{
title: "Attention!",
text: "Are you sure you want to make this",
type: "warning",
allowEscapeKey: false,
allowOutsideClick: false,
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
cancelButtonText: "No",
showLoaderOnConfirm: true,
closeOnConfirm: false
},
function (isConfirm) {
if (isConfirm) {
console.log("YES");
}
return false;
});
});
因此该功能在单击复选框后在屏幕上显示 Sweet Alert 消息,但是当我按下 Yes 按钮时,它不会 运行 console.log("YES");
.
这意味着 function (isConfirm) {
的 if (isConfirm) {
无法正常工作。
那么如何解决这个问题呢? isConfirm
有什么问题?
将此更改为:
$(document).on('click', '#btn-submit', function(e) {
e.preventDefault();
let form = $(this).parents('form');
swal(
{
title: "Attention!",
text: "Are you sure you want to make this",
type: "warning",
allowEscapeKey: false,
allowOutsideClick: false,
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
cancelButtonText: "No",
showLoaderOnConfirm: true,
closeOnConfirm: false
})
.then((isConfirm) => {
if (isConfirm) {
console.log("YES");
}
return false;
});
});
我想在提交表单后向用户显示 Sweet Alert 2 确认消息,如下所示:
<form id="myForm" data-flag="0" action="" method="POST">
@csrf
<input type="checkbox" id="btn-submit" name="wallet_checked" onchange="this.form.submit();">
</form>
如您所见,我使用 onchange="this.form.submit();"
提交了表单,但没有使用提交按钮,而且效果很好。
然后我尝试将其添加为向用户显示 SweetAlert 消息的脚本:
$(document).on('click', '#btn-submit', function(e) {
e.preventDefault();
let form = $(this).parents('form');
swal(
{
title: "Attention!",
text: "Are you sure you want to make this",
type: "warning",
allowEscapeKey: false,
allowOutsideClick: false,
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
cancelButtonText: "No",
showLoaderOnConfirm: true,
closeOnConfirm: false
},
function (isConfirm) {
if (isConfirm) {
console.log("YES");
}
return false;
});
});
因此该功能在单击复选框后在屏幕上显示 Sweet Alert 消息,但是当我按下 Yes 按钮时,它不会 运行 console.log("YES");
.
这意味着 function (isConfirm) {
的 if (isConfirm) {
无法正常工作。
那么如何解决这个问题呢? isConfirm
有什么问题?
将此更改为:
$(document).on('click', '#btn-submit', function(e) {
e.preventDefault();
let form = $(this).parents('form');
swal(
{
title: "Attention!",
text: "Are you sure you want to make this",
type: "warning",
allowEscapeKey: false,
allowOutsideClick: false,
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
cancelButtonText: "No",
showLoaderOnConfirm: true,
closeOnConfirm: false
})
.then((isConfirm) => {
if (isConfirm) {
console.log("YES");
}
return false;
});
});