jQuery:选择所有元素,其中的属性大于一个值 [英] jQuery: Selecting all elements where attribute is greater than a value

查看:1138
本文介绍了jQuery:选择所有元素,其中的属性大于一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道要过滤一个名为attrName的属性值为attrValue的元素:

I know that to filter an element with an atttribute called attrName which has value attrValue I do:

filter("[attrName='attrValue']")

但是查看docs http://api.jquery.com/category/selectors/ 我看不到选择所有元素的选项st attrName> attrValue

but looking at the docs http://api.jquery.com/category/selectors/ I can't see an option to select all elements s.t. attrName>attrValue

这将工作

   filter("[attrName>'attrValue']")


推荐答案

使用 .filter() 的函数重载,像这样:

You can do this using the function overload of .filter(), like this:

.filter(function() {
  return $(this).attr("attrName") > "someValue";
})

这篇关于jQuery:选择所有元素,其中的属性大于一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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