jq利用replace()方法实现关键字高亮显示

//1.获取要高亮显示的行
var rowNode = $('.highlightRow');
//2.获取搜索的内容
var searchContent = $("#searchContent").val();
//3.遍历整行内容,添加高亮颜色
rowNode.each(function() {
	var word = $(this).html();
	word = word.replace(searchContent, '<span style="color:red;">' + searchContent + '</span>');
	$(this).html(word);
});

猜你喜欢

转载自blog.csdn.net/qq_40924516/article/details/85157686