繁体   English   中英

用选择器隐藏父元素 具有过滤器功能(jQuery)

[英]Hiding parent element with selector | with filter function (jQuery)

我想隐藏http://ThePirateBay.se上包含少于250个种子的搜索结果 我的问题是,我不确定如何使用过滤器选项来检测种子元素,但是在检测到数字范围时也隐藏父元素。 后半部分不起作用。 感谢帮助。

$(document).ready(function(){
    var tds=$("td").filter(function() {
        if($(this).text()>250&&$(this).text()<25000){
            return this;
        }
    });
    tds.css( {"text-decoration":"underline" , "color":"#383"});
});


$(document).ready(function(){
    var tds=$("TD > #searchResult TR").filter(function() {
        if($(this).text()>001&&$(this).text()<249){
            return this;
        }
    });
    tds.css( {"opacity":"0.35" , "color":"#777"});
});

jQuery网页注入器进行自我测试: https//chrome.google.com/webstore/detail/jscript-tricks/odialddippdmebbfbflcneemfdglimod (JScript技巧)


PS,第二半部分不工作,两个零件都无法工作。

您必须先将文字解析为int,然后再进行比较

$(document).ready(function(){
    var tds = $("td").filter(function() {
        return (+$(this).text() > 250 && +$(this).text() < 25000);
    });
    tds.css( {"text-decoration":"underline" , "color":"#383"});
});


$(document).ready(function(){
    var tds = $("TD > #searchResult TR").filter(function() {
        return (+$(this).text() > 1 && +$(this).text() < 249);
    });
    tds.css( {"opacity":"0.35" , "color":"#777"});
});

您想要做的是使用jquery .parent()函数:

$(document).ready(function () {
    var tds = $("td").filter(function () {
        if ($(this).text() < 250 || $(this).text() > 25000) {
            return this;
        }
    });
    tds.parent().hide();
});

该代码将隐藏所有包含编号大于25000或小于250的元素的表行。 http://jsfiddle.net/joey6978/mwN4L/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM