function highLightText(keywords, text) {
const keys = keywords.split('')
let str = text.split('')
str.forEach((e, i) => {
if (keys.indexOf(e) > -1) {
str[i] = `<strong style="color: red">${e}</strong>`
}
})
document.body.innerHTML = str.join('')
}
highLightText('iPhone12电池', '再次曝光!iPhone12简直毫无短板,摄像头和电池提升巨大!')
复制并打开f12控制控制台点console并黏贴即可看到效果