嘿,我这里有这段代码,它会淡化页面上的所有表格,然后,如果找到了搜索词,则突出显示该词。但是,我似乎无法让它重新淡入找到搜索词的那一行。
function searchAndHighlight(searchTerm, selector) {
if(searchTerm) {
var selector = selector || "body";
var searchTermRegEx = new RegExp(searchTerm, 'ig');
var matches = $(selector).text().match(searchTermRegEx);
if(matches) {
$('.highlightedSearched').removeClass('highlightedSearched');
$(selector).html($(selector).html().replace(searchTermRegEx, "<span class='highlightedSearched'>"+searchTerm+"</span>"));
if($('.highlightedSearched:first').length) {
$(".table").each(function( index ) {
$(this).fadeTo( "slow" , 0.2, function() {
$(".highlightedSearched").each(function( index ) {
$(this).fadeTo( "slow" , 1, function() {
$('html, body').animate({scrollTop:$('.highlightedSearched:first').position().top - 130}, 'slow');
});
});
});
});
}
return true;
}
}
return false;
}
<div class="table" style="opacity: 0.2;">
<div class="row" onclick="changeChannel(3);" data-searched="name">
<span class="cell">
<img class="stationImg" src="images/logo1.jpg"><br>
<div align="center" class="Channel">Channel 3<br>name</div>
</span>
<span class="cell_2hr">
<span class="timeForShow">1:00p-3:00p<br></span>
<span class="tvShowTitle">Golf: <span class="highlightedSearched" style="opacity: 1;">The</span> Challenge<br></span>
<span class="tvEpisodeTitle"> </span>
</span>
<span class="cell_30min">
<span class="timeForShow">3:00p-3:30p<br></span>
<span class="tvShowTitle">News<br></span>
<span class="tvEpisodeTitle"> </span>
</span>
</div>
</div>
它确实有效,因为它告诉它 fadeTo 1这个:
<span class="highlightedSearched" style="opacity: 1;">The</span> Challenge<br></span>
但我需要它来查找highlightSearched所在的表类。
任何帮助都会很棒!