SweetAlert2确认对话框无法在onclick中正常工作 [英] SweetAlert2 confirm dialog not working properly in onclick
本文介绍了SweetAlert2确认对话框无法在onclick中正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何修复 sweetalert2
确认对话框在 onclick
事件按钮中无法正常工作?
How to fix the sweetalert2
confirm dialog not working properly in onclick
event button?
我有一个模式弹出窗口,用于CRUD操作,然后提交Sweetalert2确认对话框.
I have a modal popup, for CRUD operations before submitting sweetalert2 confirm dialog is triggered.
这是我的模态表单代码:
Here is my modal form code:
<form id="EditForm" asp-action="Edit">
<div class="modal-body">
/*input codes here*/
</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-success btn-flat" onclick="return submitResult()"><i class="far fa-check-circle"></i> Save Changes</button>
</div>
这是js代码:
function submitResult() {
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.isConfirmed) {
Swal.fire(
'Deleted!',
'Your file has been deleted.',
'success'
)
return true;
}
else {
return false;
}
})
}
推荐答案
尝试一下
<button type="submit" class="btn btn-success btn-flat" onclick="submitResult(event)"><i class="far fa-check-circle"></i> Save Changes</button>
....
function submitResult(e) {
e.preventDefault();
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.isConfirmed) {
Swal.fire(
'Deleted!',
'Your file has been deleted.',
'success'
)
document.getElementById("EditForm").submit();
}
})
}
这篇关于SweetAlert2确认对话框无法在onclick中正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文