jQuery检查所有选定的输入是否为空 [英] jQuery check if all of selected inputs are empty
本文介绍了jQuery检查所有选定的输入是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
测试所有选定输入是否为空的最简单方法是什么?
What is the simplest way to test if all of selected inputs are empty?
我这样得到输入:
$myinputs = $('.inputstotest');
并测试单输入:
if ( $.trim($this.val()) == '' )
但是如何测试一个组并且如果所有都为空则返回true或者如果任何(至少一个)不为空则返回false?
but how to test a group and return true if all are empty or false if any (at least one) is not empty?
推荐答案
试试这个:
var $myinputs = $('.inputstotest');
var allEmpty = $myinputs.filter(function () {
return $.trim(this.value) != '';
}).length == 0;
console.log(allEmpty);
(为了测试,在HTML标记中输入一些值,再次运行小提琴并检查控制台。)
这篇关于jQuery检查所有选定的输入是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文