jquery find div属性越小或越高 [英] jquery find div attribute smaller or higher

查看:121
本文介绍了jquery find div属性越小或越高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要找出所有div属性值符合较小或较高的数值。

i want to find all div attributed value matched smaller or higher numeric value.

它的工作只有eq value = 444(example div [ref = 444],[ref = 333] ....)

its worked me only eq value=444 (example div[ref=444],[ref=333]....)

var $ filteredData = $ data.find('div [ref = 444]');

var $filteredData = $data.find('div[ref=444]' );

但我想比较find< 444 (在所有div属性值中找到div属性值小于<444)或> 444(找到div属性值高于444)

but i want to compare find <444 ( find div attribute value smaller <444) or >444 (find div attribute value higher >444) in all div attribute value

如何找到或选择所有div attr值小于或等于
感谢所有

how can find or select all div attr value smaller or higher thanks for all

推荐答案

是的,属性是字符串,没有选择器来处理数字。您必须手动解析和 过滤器

Yes, attributes are strings, there is no selector to treat them as numbers. You would have to parse and filter manually:

$filteredData= $data.find('div').filter(function() {
    return parseInt($(this).attr('ref'), 10)<444;
});

(但是 ref ? HTML内容,这不是标准属性避免自定义HTML属性;如果您必须使用它们,请使用HTML5 data - 属性,但是其他方法,如将信息放在className中,可能会更好,取决于你在做什么。)

(But what's ref? If this is HTML content, that's not a standard attribute. Avoid custom HTML attributes; if you must use them, use HTML5 data- attributes. But other methods, such as putting the information in a className, might be better, depending on what you're doing.)

这篇关于jquery find div属性越小或越高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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