checking each required input for empty value with jQuery

后端 未结 5 1775
感情败类
感情败类 2020-12-19 11:36

I am checking for each required fields in a form. I tried this but it only works for the first input. How can I make it work for each input?

if($(\'[require         


        
5条回答
  •  天命终不由人
    2020-12-19 12:18

    Use the each() function (doc):

    $('[required]').each(function() {
        if($('[required]').val() != ''){ 
             $('.button1').fadeIn(0);
             $('.button2').fadeOut(0);
        }else{
             $('.button1').fadeOut(0);
             $('.button2').fadeIn(0);
        }
    });
    

提交回复
热议问题