本文介绍了jQuery检查是否有任何选定的输入为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果任何选定的输入为空,我将如何以简单的方式测试?
How in a simples way would I test, if any of selected inputs is empty?
我以这种方式得到我的输入:
I get my inputs this way:
$myinputs = $('.inputstotest');
并测试单输入:
if ( $.trim($this.val()) == '' )
但是如果测试一个组并且如果所有都不为空则返回true或者如果任何(至少一个)为空则返回false?
but how to test a group and return true if all are not empty or false if any (at least one) is empty?
推荐答案
我建议:
var someEmpty = $('.inputstotest').filter(function(){
return $.trim(this.value).length === 0;
}).length > 0;
使用上面的 someEmpty
将是一个布尔值, true
如果该类名的输入
带有修剪后的值值
,长度等于零。
With the above someEmpty
will be a Boolean, true
if there are inputs
of that class-name with a trimmed-value
equal to zero, false
if no inputs of that class-name have a trimmed-value
of a length equal to zero.
参考文献:
- 。
这篇关于jQuery检查是否有任何选定的输入为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!