尝试将SweetAlert2与表单发送确认一起使用。但是无论我怎么尝试,我都不能让它工作。
Swal.fire({
title: err_msg,
//html: strCEmail,
text: 'hello',
type: 'question',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, send it!'
}).then((result) => {
if (result.value) {
// xxxxxxxxxxxxxxxxxxxx
}
}); 代码达到了xxxxxxxxxxxxx,但是无论我放在哪里,都不会触发表单提交。
我试过显而易见的
return true;但这并不管用。然后,经过一些挖掘,我发现了提交表单的建议,如下所示:
document.forms["myform"].submit();或form.submit();
但这并不管用。
所以..。用户在SweetAlert2中选择submit后,我可以使用什么来提交表单?
发布于 2019-05-01 02:59:57
最有可能的情况是,您正在尝试访问不存在的内容。基于SWAL文档和这篇文章:结果你应该试着做“if( Response from Sweet-alert confirm dialog )”而不是"if(result.value)“。
此外,正如我上面所评论的,您应该通读文档并阅读精灵宝可梦示例,它可能会给您一个提示:sweetalert.js.org t.js.org/guides/#advanced-examples
发布于 2019-05-29 20:12:10
为窗体提供id
<form action="your-action" method="post" id="my_form">在js中:
Swal.fire({
title: err_msg,
text: 'hello',
type: 'question',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, send it!'
}).then((result) => {
if (result.value) {
$(document).find('#my_form').submit();
}
});https://stackoverflow.com/questions/55927021
复制相似问题