题解 | #字体高亮#
字体高亮
http://www.nowcoder.com/practice/1b7437b538af4689b1509db2068abe55
var text = document.querySelector(".text");
var search = document.querySelector("input");
const btn = document.querySelector("button");
var article=String(text.innerText)//保存原文本
btn.onclick = () => {
// 补全代码
var key=new String(search.value)
var newV=article.replace(new RegExp(key,'g'),`
<b style="background-color:yellow">${key}</b>
`)
text.innerHTML=newV
}