jQuery Validate plugin, enable submit button when form is valid

前端 未结 4 823
感动是毒
感动是毒 2020-12-15 11:50

I have an enabled and disabled state for the submit button on my form.

The conditions are as follows:

If all input fields have been entered and are

4条回答
  •  有刺的猬
    2020-12-15 12:05

    $('form').find(':input').each(function(index, value){
        //action for every element
        $(value);
    });
    

    In this case you can do this that way: (but I dont like this solution)

    var areSomeFieldsEmpty = false;
    $('form').find(':input').each(function(i, v){
      if ($(v).val().length <= 0){
         areSomeFieldsEmpty = true;
      }
    });
    
    if (!areSomeFieldsEmpty){
      //unlock form   
    }
    

    http://jsfiddle.net/89y26/335/

提交回复
热议问题