0

如果至少有 2 个名称为选项 [] 的输入被填充,我需要 value is not empty 选择器来计数。我之前有 jquery 1.7.2 而不是 value!="" 选择器工作。

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

现在我升级了 jquery 1.9.1,这总是返回所有字段的数量,因为所有字段都被填充了,即使它们都没有被填充。有没有其他选择?

4

2 回答 2

1

That's not working anymore because there's a difference between the current value of a field and the value attribute (which typically holds the original value as of when the HTML was parsed).

You'll probably have to throw a not in there:

$('input[name="choices[]"]').not(function() {
    return !!this.value;
}).length

...or filter:

$('input[name="choices[]"]').not(function() {
    return !this.value;
}).length
于 2013-04-27T10:05:23.800 回答
0

你可以简单地这样做:

$('input[name="choices[]"]').filter(function() {
     return $(this).val() != "";
}).length
于 2013-04-27T10:11:19.990 回答