这不行,应该吗?或者,如果另一行可以执行相同操作,您可以停止错误:
function doTheHighlightning(searchTerms) {
    // loop through input array of search terms
    myArray = searchTerms.split(" ");
    for(i=0;i<myArray.length;i++)
    {
        // works. this line works if not out commented. Will highlight all words, also in the hidden elements
        //$('tbody').highlight(myArray[i]);
        // not working when trying to skip elements with display none...
        $('tbody').css('display') != 'none').highlight(myArray[i]);
    }
    // set background to yellow for highlighted words
    $(".highlight").css({ backgroundColor: "#FFFF88" });
}
我需要过滤表格中的行并为某些单词着色.如果选择了很多单词,数据已经成为着色的方法.因此,我将尝试通过仅通过无隐藏元素来限制着色.
use*_*716 44
如果你想获得可见tbody元素,你可以这样做:
$('tbody:visible').highlight(myArray[i]);
它看起来类似于Agent_9191给出的答案,但是这个从选择器中移除了空格,这使得它选择可见tbody元素而不是可见后代.
编辑:
如果您特别想display在tbody元素的CSS属性上使用测试,则可以执行以下操作:
$('tbody').filter(function() {
     return $(this).css('display') != 'none';
}).highlight(myArray[i]);
Zuu*_*uul 43
使用这样:
if( $('#foo').is(':visible') ) {
    // it's visible, do something
}
else {
    // it's not visible so do something else
}
希望能帮助到你!
试着这样做只选择下面的可见元素tbody:
$('tbody :visible').highlight(myArray[i]);
| 归档时间: | 
 | 
| 查看次数: | 120969 次 | 
| 最近记录: |