我创建了一个具有演示登录功能的应用程序。 Demo 登录将弹出一个甜蜜的警报,让用户知道他们所做的更改不会保存到数据库中。问题在于,在用户按下将关闭甜蜜警报的确定按钮后,表单不会提交。按下确定按钮后提交表单的正确语法是什么?
下面是我的html
:
<form method="post" id="submitForm" name="demoSubmitForm">
<div class="demo-button pt-3">
<button type="button" name="demoEmail" value="DemoEmail" class="au-btn au-btn--block au-btn--blue
m-b-20" onclick="ShowSweetAlert()">
Demo Application
</button>
</div>
</form>
下面是我的脚本:
function ShowSweetAlert() {
Swal.fire({
icon: 'warning',
title: 'You are logging in as a Demo User!',
text: 'Changes you make to the Application will not be saved once you log out.',
onClose: document.getElementById('submitForm').submit() /*document.demoSubmitForm.submit()*/
});
}
目前 document.demoSubmitForm.submit()
和 document.getElementById('submitForm').submit()
都无法提交表单。
答案 0 :(得分:0)
添加此Script
:
$('#submitForm').on('click', function(e) {
e.preventDefault();
var form = $(this).parents('form');
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false
}, function(isConfirm) {
if (isConfirm) form.submit();
});
});