通过Javascript/JQUERY中的某个'Submit'按钮提交表单



我有一个包含多个input type submit按钮的表单,每个按钮都有一个不同的name属性,倾向于POST不同的信息。

我正在尝试使用SweetAlert作为一种验证形式。

然而,我面临的问题是,当我放入SweetAlert代码(因此需要e.preventDefault()(时,它会发布并提交,但使用默认的Submit,它不会将正确的信息发布到后端(django-python应用程序(。

$('.customSubmit').on('click',function(e){
e.preventDefault();
Swal.fire({
title: 'Are you sure?',
text: "You're about to do XXXX.",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#6b84a3',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes!'
}).then((result) => {
if (result.value) {
// This is where I want to make sure that my form submits via a particular submit button
$('#myForm').submit();
}
});
});

这是我想用于提交表单的输入

<input type="submit" class="btn btn-primary customSubmit" name="customSubmit" value="Submit" />

这是我的表格

<form action="" method="post" name="myForm" id="myForm" enctype="multipart/form-data" class="form-with-datepicker">
<input class="text" type="checkbox" value="Name" name="form_name" />
<input type="submit" class="btn btn-primary submitDelete" name="submitDelete" value="Delete" />
<input type="submit" class="btn btn-primary customSubmit" name="customSubmit" value="Submit" />
</form>

而不是使用

<input type="submit" class="btn btn-primary submitDelete" name="submitDelete" value="Delete" />

这个u将尝试使用这个

<button type="submit" name="" class=""></button>

第二个按钮也有不同级别的

最新更新