页面的字段高亮怎么做?

可能有些需求会有一些做字段高亮的需求,简单粗暴一点的方法就是 

let seachText = '枚举';
const regexp = new RegExp(seachText, 'g');
let content = $('#content').html();
let newHtml = content.replace(regexp, '<span class="highlight-word" style="background: #ff0; color: #f00;">' + seachText + '</span>');
$('#content').html(newHtml);

  

 

原文地址:https://www.cnblogs.com/tipsydr/p/15752752.html