Javascript JQuery突出显示搜索词的文本
我想高亮显示(或背景色)过滤行中搜索词的输入文本$('#Search').val()。我试着用一个span来包装它,添加了一个类并直接添加了CSS-不起作用 搜索框(输入)具有id=“搜索”Javascript JQuery突出显示搜索词的文本,javascript,jquery,css,Javascript,Jquery,Css,我想高亮显示(或背景色)过滤行中搜索词的输入文本$('#Search').val()。我试着用一个span来包装它,添加了一个类并直接添加了CSS-不起作用 搜索框(输入)具有id=“搜索” 搜索: 表id=“vw” 请提供HTML代码所有集合-添加的HTML代码请提供用于在搜索结果中突出显示文本的代码。 <p> <span>Search:</span> <input type="text" id="Search" name="Search" ma
搜索:
表id=“vw”
请提供HTML代码所有集合-添加的HTML代码请提供用于在搜索结果中突出显示文本的代码。
<p>
<span>Search:</span>
<input type="text" id="Search" name="Search" maxlength="20" placeholder="Search" />
</p>
<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();
}