Button disable unless both input fields have value

前端 未结 4 1433
野性不改
野性不改 2021-01-06 16:31

I have a form with two input fields and a submit button on my page, I would like to have the feature that the \'submit\' button is disabled until there are

4条回答
  •  一整个雨季
    2021-01-06 17:27

    $(function(){
      $("#first_name, #second_name").bind("change keyup",
      function(){
         if($("#first_name").val() != "" && $("#second_name").val() != "")
            $(this).closest("form").find(":submit").removeAttr("disabled");
         else
            $(this).closest("form").find(":submit").attr("disabled","disabled"); 
      });
    });
    

提交回复
热议问题