这不工作,应该吗?或者你可以停止错误,如果另一行可以做同样的:
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" }); }
我需要过滤表中的行和颜色一些词。如果选择了许多单词,数据已经成为着色的方法。所以我会尽量限制着色只通过无隐藏元素。
解决方法
如果你想获得可见的tbody元素,你可以这样做:
$('tbody:visible').highlight(myArray[i]);
它看起来类似于Agent_9191给出的答案,但是这会从选择器中删除空格,这使得它选择可见的tbody元素而不是可见的后代。
编辑:
如果你特别想在tbody元素的显示CSS属性上使用测试,你可以这样做:
$('tbody').filter(function() { return $(this).css('display') != 'none'; }).highlight(myArray[i]);