jQuery:如果数值范围从0开始,.parent()不会隐藏 [英] jQuery: .parent() wont hide if numerical range begins at 0

查看:86
本文介绍了jQuery:如果数值范围从0开始,.parent()不会隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个元素内使用数值范围检测以隐藏另一个元素时,我遇到了一些问题.当范围从1+开始,但在0+处断开时,它似乎工作正常.它们是我尝试过的不同代码迭代,但到目前为止还算不上成功.

这是我尝试在以下网站上使用我的油脂猴子脚本的网站: https://openuserjs.org/?orderBy=updated&orderDir=desc

目的:如果安装0-100次,我想隐藏一个列出的项目.

这是我的脚本: https://ghostbin.com/paste/zujku

这是我尝试使用但失败的三种代码:

$("TR .text-center.td-fit").each(function() { 
if ($(this).text() >= 0 && $(this).text() <= 100){
$(this).parent().hide();
}
});


$(document).ready(function(){
var tds = $("TR .text-center.td-fit").filter(function() {
return (+$(this).text() > 0 && +$(this).text() < 100);
});
tds.parent().hide();
});


$("TR .text-center.td-fit").each(function() { 
if ($(this).text() >= 0 && $(this).text() <= 100){
$(this).parent().hide();
}
});

注意:.text-center.td-fit"是主列表项(TR)上的安装"元素

解决方案

尝试一下:

$("tr.tr-link").each(function() { 
    var num = parseInt($(this).find('td.text-center.td-fit > p').first().text());
    if (num >= 0 && num <= 100) {
        $(this).hide();
    }
});

I am having some issues with using a numerical range detection within an element, to then hide another element. It seems to work fine when the range starts at 1+, but it breaks at 0+. Their are different iterations of code I have tried, but so far no luck.

This is the website I am trying to use my greasemonkey script on: https://openuserjs.org/?orderBy=updated&orderDir=desc

The purpose: I would like to hide a listed item, if it has 0-100 installs.

Here is my script: https://ghostbin.com/paste/zujku

Here are the three variations of code I have tried using but failed:

$("TR .text-center.td-fit").each(function() { 
if ($(this).text() >= 0 && $(this).text() <= 100){
$(this).parent().hide();
}
});


$(document).ready(function(){
var tds = $("TR .text-center.td-fit").filter(function() {
return (+$(this).text() > 0 && +$(this).text() < 100);
});
tds.parent().hide();
});


$("TR .text-center.td-fit").each(function() { 
if ($(this).text() >= 0 && $(this).text() <= 100){
$(this).parent().hide();
}
});

Note: ".text-center.td-fit" is the 'installs' element on the main list item (TR)

解决方案

Try this:

$("tr.tr-link").each(function() { 
    var num = parseInt($(this).find('td.text-center.td-fit > p').first().text());
    if (num >= 0 && num <= 100) {
        $(this).hide();
    }
});

这篇关于jQuery:如果数值范围从0开始,.parent()不会隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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