"任何" jquery中的布尔函数 [英] "Any" boolean function in jquery

查看:88
本文介绍了"任何" jquery中的布尔函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何 easy 方法来检查jquery选择器中的任何元素是否满足条件?例如,要检查表单中的任何文本框是否为空(伪种类,而不是真正的jquery):

Is there any easy way to check if any elements in a jquery selector fulfill a condition? For instance, to check if any textboxes in a form are empty (kind of pseudo, not real jquery):

$('input.tb').any(val().length == 0);

注意:我知道可以用辅助方法完成,只是好奇如果有可能在一个声明。

Note: I know it could be done with a helper method, just curious if it was possible in one statement.

推荐答案

jQuery内置了很多伪选择器: http://api.jquery.com/category/selectors/jquery-selector-extensions/

jQuery has a lot of pseudo selectors built in: http://api.jquery.com/category/selectors/jquery-selector-extensions/

您还可以使用 filter()功能构建自己的功能: http: //api.jquery.com/filter/

You can also build your own with the filter() function: http://api.jquery.com/filter/

$('input.tb').filter(function() { return this.value.length == 0});

这篇关于"任何" jquery中的布尔函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆