SweetAlert 2 - 表单提交(超出最大调用堆栈大小)



我在使用SweetAlert 2时遇到问题,当用户单击"确定"时,我正在尝试提交表单。

代码如下(使用jQuery(

$('#sa-params').click(function(e) {
e.preventDefault();
e.stopPropagation();
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!',
cancelButtonText: 'No, cancel!',
confirmButtonClass: 'btn btn-success',
cancelButtonClass: 'btn btn-danger',
buttonsStyling: false
}).then(function () {
swal(
'Deleted!',
'It has been deleted, FOREVER!',
'success'
)
$('form#delete-form').submit();
}, function (dismiss) {
if (dismiss === 'cancel') {
swal(
'Cancelled',
'Relax, nothing has been deleted :)',
'error'
)
}
})
return false;
});

收到以下 JavaScript 错误:

Uncaught (in promise) RangeError: Maximum call stack size exceeded

最主要的是,如果我用console.log('success')错误替换表单提交,则不会显示。

根据bower.json的说法:

j查询版本为:2.2.4

SweetAlert2版本是:5.3.8

$('form#delete-form')[0].submit();

解决了我的问题,我不知道为什么我没有尝试过...

解决方案 在您的文件中 甜蜜警报.js

注释掉:

$targetElement.focus(); 

或在您的文件中 sweetalert.min.js

b.focus()

可能在 413 行。

来源: https://github.com/t4t5/sweetalert/issues/104

最新更新