我想突出显示(或背景颜色)过滤行中搜索词的输入文本$('#Search')。val()。我试图用一个跨度包装它,添加了一个类并直接添加了CSS-不起作用...
搜索框(输入)的ID为“搜索”
<p>
<span>Search:</span>
<input type="text" id="Search" name="Search" maxlength="20" placeholder="Search" />
</p>
表id =“ vw”
<table id='<?php echo $vw;'>
<thead>
<tr>
<th>
<th>
<th>
</tr>
</thead>
<tbody>
<tr>
<td>
<td>
<td>
</tr>
</tbody>
</table>
$('#Search').keyup(function() {
// only search when there are 3 or more characters in the textbox
if ($('#Search').val().length > 2) {
// hide all rows
$('#' + vw + ' tr').hide();
// show the header row
$('#' + vw + ' tr:first').show();
// show the matching rows (using the containsNoCase)
$('#' + vw + ' tr td:containsNoCase(\'' + $('#Search').val() + '\')').parent().show();
// HERE - Want to hightlight(or background-color) the input text $('#Search').val() in the filtered row
// change css class to show all white records
$('#' + vw + ' tr:nth-of-type(odd)').css('background', '#fff');
} else if ($('#Search').val().length == 0) {
// if the user removed all of the text, reset the search
resetSearch();
}