javascript - 突出显示搜索的关键字
问题描述
我正在突出显示我搜索的关键字 - 但是它会搜索 HTML,所以如果我有类似的东西
<a href="espn.com?id=456">espn</a>
并在 456 上搜索 - 它找到了 - 我不想要那个。
这就是我正在使用的
function highlightOnly(text) {
$('#' + view + ' td').each(function(i, e) {
var $e = $(e);
$e.html($(e).html().split(text).join('<span class="matching">' + text + '</span>'));
})
}
$('.matching').replaceWith(function() {
return this.innerText;
});
highlightOnly($('#txtSearch').val().toUpperCase());
你可以在这里看到原始小提琴 搜索关键字突出显示
解决方案
推荐阅读
- typescript - 在 Typescript 3.9 中使用两个依赖类型参数索引嵌套对象失败
- java - java 类和“import com.google.gson.*”错误
- c - rename() 如何在 C 的引擎盖下实际工作?
- c# - Windows 将多个控件合二为一
- python - 是否有允许团队通过类似 git 的界面共享 venvs 的 python 包?
- microcontroller - 为什么我们在信号量中使用 ISR 函数?
- twitter - Tweepy 机器人发推特 DM
- javascript - 如何在隐藏元素上停止 setinterval
- pandas - 按最多三列对 pandas 数据框中的示例进行排序
- hex - \x00@ 是什么意思?