简体   繁体   English

填写所有字段后启用提交按钮

[英]Enable submit button after all fields are filled

I have a jquery toggling menu with password fields. 我有一个带有密码字段的jquery切换菜单。 By default, the submit button is disabled, and enabled on keyup events. 默认情况下,“提交”按钮是禁用的,并在键入事件时启用。

$(function(){
  $("#submitProfile").attr("disabled","true");
  $("#password_confirmation, #password, #current_password").keyup(function(){
    $("#submitProfile").removeAttr("disabled");
  });
});

But how can I keep the button disabled until all the fields are filled? 但是,如何在所有字段都填满之前使按钮保持禁用状态?

You can add a condition. 您可以添加条件。

$(function(){
  $("#submitProfile").attr("disabled","true");
  $("#password_confirmation, #password, #current_password").keyup(function(){
      if($("#password_confirmation").val() && $("#password").val() && $("#current_password").val())
          $("#submitProfile").removeAttr("disabled");
  });
});

Live demo 现场演示

You can try something like this:- 您可以尝试这样的事情:

if($('#password_confirmation, #password, #current_password').val().length>0){
 $("#submitProfile").removeAttr("disabled");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM