【发布时间】:2016-06-24 00:19:57
【问题描述】:
在我的 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();
}
});
【问题讨论】:
-
顺便说一句,您应该删除
onclick属性并在submit处理程序中调用goog_report_conversion()和ToGetTrackingCode()。此外,添加/删除类而不是覆盖元素上的style属性会更好。 -
@RoryMcCrossan 你认为这会导致问题吗?!
-
我不知道根本原因是什么,但是为什么要定义一个 onclick 处理程序来仅通过单击来报告转换?您是否打算在点击和验证码都成功时报告转化,或者您想跟踪所有点击量而不管验证码是否成功?无论如何,我同意@RoryMcCrossan 的所有逻辑都应该在提交本身中。我不喜欢在不同的地方添加多个处理程序的想法。
标签: javascript php jquery html css