开发者

jQuery count non-empty fields

Trying to count the number of input fields of class '.booked' that are NOT empty (ie开发者_如何学C they have some kind of value entered.

For some reason this is not doing it for me. Someone please put me out of my misery :)

$('input.booked:not(:empty)').length


Try this:

$('input.booked[value!=""]').length

empty returns nodes with no children, which isn't what you want.


the :empty selector filters to elements that have no child nodes. What you want is an attribute equals selector...

$("input.booked:not([value=''])").length
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜