【发布时间】:2017-09-03 09:21:24
【问题描述】:
我正在尝试实现表格搜索,我在网上找到了答案并试了一下,效果很好!
现在我想突出显示 (change text colour: text color class= blue-text) 在表格单元格中找到的搜索关键字,我搜索了这个答案,但没有找到任何有用的信息!
我的 HTML 是
<table class="stdtable">
<tr>
<td id="stdname">Name</td>
<td id="stdreg">Reg. No.</td>
<td id="stdparent">Parent</td>
<td id="stdgrp">Group</td>
<td id="action">Action</td>
</tr>
</table>
Jquery 是
$("#filter").on("keyup", function() {
var searchKey = $(this).val().toLowerCase();
$(".stdtable tr #stdname").each( function() {
var searchStr = $(this).text().toLowerCase();
if (searchStr.indexOf(searchKey)!=-1) {
$(this).parent().show();
}
else {
$(this).parent().hide();
}
});
});
如何突出显示搜索到的文本? 如果我搜索 N,Name 中的文本 N 应该会改变颜色
如果我清除搜索字段,我还需要清除文本的颜色
【问题讨论】:
-
试试mark.js?
标签: javascript jquery html search colors