Jquery selector to find out count of non empty inputs

前端 未结 2 652
粉色の甜心
粉色の甜心 2021-02-19 01:42

I have the below HTML DOM

      

相关标签:
2条回答
  • 2021-02-19 02:05

    You can pass in a filter function rather than a selector:

    $('#container input[type="text"]').filter(function () {
        return !!this.value;
    }).length;
    
    0 讨论(0)
  • 2021-02-19 02:22

    The attribute value will always be the default value so you must filter through the input boxes and check the value like this code below

    $('#container input[type="text"]').filter(function () {
        return this.value.length > 0
    }).length;
    

    DEMO

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