jQuery表单,禁用“提交"按钮,直到输入了必填字段 [英] Jquery form, disable submit button until required field entered

查看:184
本文介绍了jQuery表单,禁用“提交"按钮,直到输入了必填字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用提交按钮来启用1st,直到用户单击提交"(如果验证失败).禁用提交按钮,直到输入了所有必填字段

I need the submit button to enable 1st, until user click submit if validation failed. submit button disable until all the required field are entered

推荐答案

浏览表单字段,检查是否还有任何字段保留为空,如果是,则保持禁用提交按钮,否则启用提交按钮.

Loop through the form fields and check if there is any field/s still left out empty, if yes keep disabled submit button, else enable submit button.

var flag = true;

$('#yourFormID').each(function() 
   {  
       if($(this).val() == "")  
       { 
             /* $('input[type="submit"]').attr('disabled'); may be you will need this if you are checking form on every form element*/
              flag = false;
       }
   }
if(flag) {
        $('input[type="submit"]').removeAttr('disabled');
}

我建议您在表单的最后一个元素上调用此代码

I will suggest to call this code on on last element of your form

这篇关于jQuery表单,禁用“提交"按钮,直到输入了必填字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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