[英]Disabling submit Button after click will prevent submiting form in Chrome
我最近遇到了,至少对我来说,有趣的错误。 如果表单中没有验证错误,我们已经制作了禁用提交按钮的 JS 以防止多个表单发送等。这在 Firefox 中工作得很好。 但是,这在 chrome 中无论如何都行不通。
如果一切正常,这是我验证表单和禁用按钮的逻辑。
$('body').on('click', "button[type='submit']", function (evt) {
MessageBox.RemoveAllBoxes();
if (!CustomDynamicValidation()) {
//Something went wrong
return false;
}
//Everything is ok. Disable button and send
$(this).attr('disabled', true);
return true;
});
这适用于 Firefox。 单击并发送表单后,按钮被禁用。 在 Chrome 中按钮被禁用但未发送表单。
我认为如果我在 Timeout 中设置 disable ,它甚至可以在 chrome 中开始工作。 喜欢:
$('body').on('click', "button[type='submit']", function (evt) {
var submitButton = $(this);
MessageBox.RemoveAllBoxes();
if (!CustomDynamicValidation()) {
//Something went wrong
return false;
}
//Everything is ok. Disable button and send
setTimeout(function () { $(button).attr('disabled', true); }, 0);
return true;
});
我的问题是为什么会这样? 为什么即使 chrome 工作零延迟也需要超时? 或者,是否有更优雅的解决方案?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.