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

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

问题描述

我知道要过滤具有名为 attrName 的属性的元素,该属性具有值 attrValue 我这样做:

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

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

但查看文档 http://api.jquery.com/category/selectors/ 我看不到选择所有元素的选项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天全站免登陆