counting number of empty inputs with a certain class

前端 未结 3 1361
-上瘾入骨i
-上瘾入骨i 2020-12-16 04:34

I have tried a couple of solutions from previous questions, but no luck. Hoping someone can help me out.

I have a section of a form where fields are dynamically crea

相关标签:
3条回答
  • 2020-12-16 05:04

    This will give you all empty inputs:

    $('.user_field').filter(function(){
        return !$(this).val();
    }).length;
    
    0 讨论(0)
  • 2020-12-16 05:11
    $('.user_field').blur(function(){
        alert ($('.user_field').filter('[value=""]').length);
    });
    

    DEMO

    0 讨论(0)
  • 2020-12-16 05:13

    mm just posting my version using .not

    $('.user_field').blur(function() {
       var count = $('.user_field').not(function() {
            return this.value;
        }).length;
    
        alert(count);
    });
    

    DEMO

    0 讨论(0)
提交回复
热议问题