常见的jQuery在HTML5验证后禁用所有表单上的提交按钮 [英] Common jQuery to disable submit buttons on all forms after HTML5 validation

查看:223
本文介绍了常见的jQuery在HTML5验证后禁用所有表单上的提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请原谅我,如果它是一个基本的东西,因为我是一个新的Javascript / jQuery的学习者。我一直试图禁用提交按钮来禁用多个提交。我在这里也遇到了多种解决方案,但所有这些都使用了特定的表单名称。但我想为所有页面上的所有表单应用全局解决方案,所以我不必在每个页面上编写代码,因此我将它放在页脚中,所以所有页面都有:

< 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验证完成后才会禁用。谢谢

解决方案

试试这个,让我知道:

 $($)$('input:submit')。 ('input:submit')。attr(disabled,true); 
$('。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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆