A cópia do código é a seguinte:
<! Doctype html public "-// w3c // dtd xhtml 1.0 transitional // pt" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-bransitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text /html; charset = utf-8" />
<title> Palavra -chave Destaque </title>
</head>
<Body>
<div id = "TextBox">
<p> Baidu (NASDAQ BIDU) é o maior mecanismo de busca chinês do mundo.
Método de aquisição de informações. A palavra "Baidu" originou -se da letra de "Qingyu Case · Yuanxi", de Xin Qiji, um poeta da dinastia Song na China, "procurando por ele milhares de quilômetros da multidão", simbolizando a busca persistente de Baidu na recuperação de informações chinesas . </p>
</div>
<Cript>
Função Destaque (idVal, palavra -chave) {
var textBox = document.getElementById (idVal);
if ("" == palavra -chave) retornar;
// Obtenha todo o conteúdo de texto
var temp = textbox.innerhtml;
console.log (temp);
var htmlreg = novo regexp ("/<.*?/>", "i");
var arr = new Array ();
// Substitua a tag html
for (var i = 0; true; i ++) {
// Combine a tag html
var tag = htmlreg.exec (temp);
if (tag) {
arr [i] = tag;
} outro {
quebrar;
}
temp = temp.replace (tag, "{[(" + i + ")]}");
}
// falando sobre divisão de palavras -chave e incorporar em matrizes
palavras = decodeuricomponent (palavra -chave.replace (//,/g, '')). split (// s+/);
// Substitua a palavra -chave
for (w = 0; w <words.length; w ++) {
// corresponde a palavras -chave e reter caracteres especiais que podem aparecer nas palavras -chave
var r = new regexp ("(" + palavras [w] .Rearplace (/[() {}.+*?^$ | /// [/]]/g, "// $ &") + ") "," IG ");
temp = temp.replace (r, "<byle = 'cor: vermelho;'> $ 1 </b>");
}
// Restaure as tags HTML
for (var i = 0; i <arn.length; i ++) {
temp = temp.replace ("{[(" + i + ")]}", arr [i]);
}
textbox.innerhtml = temp;
}
destaque ("TextBox", "Baidu, Robin Li");
</script>
</body>
</html>