btn.onclick = () => { // 补全代码 let mytext = text.innerText; let myvalue = new RegExp(search.value,'g'); if(search.value!==''){ mytext = mytext.replace(myvalue, `<b style="background:yellow;">${search.value}</b>`); } text.innerHTML = mytext; };