常见的jQuery在HTML5验证后禁用所有表单上的提交按钮 [英] Common jQuery to disable submit buttons on all forms after HTML5 validation
问题描述
< pre'
$('input:submit')。click(function(){
$('input:submit')。attr(disabled,true);
});
此代码适用于所有页面中的所有表单,但是如果有HTML5必填字段在形式和形式提交没有他们,当然通知弹出,但按钮仍然被禁用。所以,我尝试了这一点:
$('input:submit')。click(function(){
if($(this).valid()){
$('input:submit')。attr(disabled,true);
$('。button')。hide();
});
});
但这不起作用。请帮助我,让jQuery只在所有HTML5验证完成后才会禁用。谢谢
试试这个,让我知道:
$('。button')。hide();
});
});
Please pardon me if it is a basic thing, because I am a new learner of Javascript/jQuery. I have been trying to disable submit button to disable multiple submits. I have come across multiple solutions here as well, but all those used specific form name. But I wanted to apply a global solution for all forms on all pages so I dont have to write code on each page, so I put this in footer, so all pages have:
$('input:submit').click(function(){
$('input:submit').attr("disabled", true);
});
This code works on all the forms in all pages as I wanted, but if there are HTML5 required fields in form and form is submitted without them, of course notifications are popped but button still gets disabled. So, I tried with this:
$('input:submit').click(function(){
if ($(this).valid()) {
$('input:submit').attr("disabled", true);
$('.button').hide();
});
});
But this does not work. Kindly help me so that jQuery only disables when all HTML5 validation is done. Thanks
Try this and let me know:
$('input:submit').click(function(){
if ($(this).closest("form").checkValidity()) {
$('input:submit').attr("disabled", true);
$('.button').hide();
});
});
这篇关于常见的jQuery在HTML5验证后禁用所有表单上的提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!