多个关键词加红
lightWord(article, oldWord){
for (const key of oldWord){
let regExp = new RegExp(key, 'g');//正则表达式方法,完全匹配对应的关键字,且声明全局
article = article.replace(regExp, `<span style="color:#f00">${key}</span>`);
}
return article;
}
//第一个参数是要加红的文字部分,第二个参数是关键词
this.lightWord(that.list.content,that.keywords)
//在哪显示
$('.main').html(that.lightWord(that.list.content,that.keywords))