jQuery: 如果数值范围从 0 开始,.parent() 不会隐藏
jQuery: .parent() wont hide if numerical range begins at 0
我在使用元素内的数值范围检测然后隐藏另一个元素时遇到了一些问题。当范围从 1+ 开始时它似乎工作正常,但它在 0+ 时中断。它们是我尝试过的不同代码迭代,但到目前为止运气不好。
这是我尝试使用我的 greasemonkey 脚本的网站:
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)
上的 'installs' 元素
我使用 Firefox 附加商店中的 AdBlock 元素隐藏器来解决这个问题。有了几个 combinations/try,我发现这个组合很有效
AdBlock 元素隐藏器选择:
THEAD + * TD:first-child + .text-center.td-fit > P
当前工作版本:
$("THEAD + * TD:first-child + .text-center.td-fit > P").each(function() {
if ($(this).text() >= 0 && $(this).text() <= 70){
$(this).parent().parent().hide();
}
});
试试这个:
$("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();
}
});
我在使用元素内的数值范围检测然后隐藏另一个元素时遇到了一些问题。当范围从 1+ 开始时它似乎工作正常,但它在 0+ 时中断。它们是我尝试过的不同代码迭代,但到目前为止运气不好。
这是我尝试使用我的 greasemonkey 脚本的网站: 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)
上的 'installs' 元素我使用 Firefox 附加商店中的 AdBlock 元素隐藏器来解决这个问题。有了几个 combinations/try,我发现这个组合很有效
AdBlock 元素隐藏器选择:
THEAD + * TD:first-child + .text-center.td-fit > P
当前工作版本:
$("THEAD + * TD:first-child + .text-center.td-fit > P").each(function() {
if ($(this).text() >= 0 && $(this).text() <= 70){
$(this).parent().parent().hide();
}
});
试试这个:
$("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();
}
});