在我的 HTML 表单中,当我单击“提交”按钮时,它会被禁用,因此用户无法单击它两次。此按钮发送一封电子邮件,但当我测试此表单时,有时按钮会执行该操作两次,尽管我单击它一次,有时它工作正常并且仅执行该操作一次。这是我的代码:
<form id="request-form" action="http://premitek.slayer.nabdsys.com/UserAccount/Create" class="contact-form">
<input name="txt" id="txt" type="text">
<input value="Sign up"
id="btnSignUp"
onclick="goog_report_conversion();ToGetTrackingCode();"
class="btn btn-primary btn-lg"
data-loading-text="Loading..."
type="submit">
</form>
$("form").submit(function (e) {
if ($('#CaptchaEnter').val().toLowerCase() != $('#randomfield').val().toLowerCase() || $('#CaptchaEnter').val() == "") {
e.preventDefault();
$('#captcha').attr(
"style",
"border-color: #a94442; box-shadow: inset 0 1px 1px"
);
$('#verCapacha').show();
} else {
$('#captcha').attr("style","");
$('#verCapacha').hide();
$('#btnSignUp').prop('disabled', true);
ShowProgress();
}
});
最佳答案
您的页面上只有一个表单标签吗?您已经为每个表单元素设置了提交功能。您可能应该通过表单 ID 来设置它。
此外,当您说“执行操作”时,您的意思是发送电子邮件吗?或者运行JS函数?如果是电子邮件,请检查以确保没有其他方法可以访问电子邮件代码,包括刷新页面。
关于javascript - 提交按钮有时会以 html 形式执行两次操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35894743/