jQuery:选择所有元素,其中的属性大于一个值

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";
})