禁用就可以了,当点击提交按钮,将prevent从谷歌浏览器提交表单 [英] Disabling a submit button when clicking on it , will prevent the form from being submitted on Google Chrome
问题描述
我添加下面的脚本到我的布局来看,我的asp.net mvc的内部: -
I have added the following script to my layout view, inside my asp.net mvc :-
$(document).ready(function () {
$('.btn.btn-primary').click(function () {
$(this).prop("disabled", true);
if (!$('form').valid()) {
$(this).prop("disabled", false);
return false;
}
});
$('form').change(function () {
$('.btn.btn-primary').prop("disabled", false);
});
我的脚本的目的是禁用提交按钮,并且如果该模型是无效重新启用它们或者如果用户改变一个表格值。以上脚本将在IE浏览器和放大器以及工作;火狐,但在Chrome我无法提交表单,当用户点击提交按钮,该按钮会关闭,但形式会不会被提交。任何想法如何解决在Chrome这个问题?
The aim of my script is to disable the submit buttons , and re-enable them if the model is not valid or if the user change a form value. The above script will work well on IE & Firefox, but on Chrome I am unable to submit the form , as when the user clicks on the submit button , the button will be disable but the form will not be submitted. Any idea how I can solve this issue on Chrome?
推荐答案
而不是禁用的按钮的Click事件按钮 - 在表单提交事件禁用它(您可以检查表的有效性有作为)
Instead disabling button in button's click event - disable it in form's submit event (you can check form for validity there as well).
这种方法能够在所有浏览器普遍使用。
This way it will work universally in all browsers.
<form action="http://www.microsoft.com">
<input class="btn-primary" type="submit" value="submit"/>
</form>
$('form').submit(function() {
$('input.btn-primary').prop("disabled", "disabled");
})
这篇关于禁用就可以了,当点击提交按钮,将prevent从谷歌浏览器提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!