Code
< Pre >
Use js Article Highlight the specified keyword in the content
Yes ..
These keywords: beauty, life, and shopping
When these keywords appear in the article, highlight them ..
The article generates static pages, and these keywords can be updated at any time, so I want to use js to implement it...
I don't know how to implement this function. ? Here for help
< / PRE>
< Script Language = " Javascript " >
Function Highlight (key ){
VaR Key = Key. Split ( ' | ' );
For ( VaR I = 0 ; I < Key. length; I ++ ){
VaR RNG = Document. Body. createTextRange ();
While (RNG. findtext (Key [I])
// RNG. pastehtml (RNG. Text. fontcolor ('red '));
RNG. pastehtml ( ' <Div style = "border: 1 solid red; display: inline"> <a href = "#" Title = ' + RNG. Text + ' > ' + RNG. Text + ' </A> </div> ' );
}
}
Highlight ( ' Article | key | Function ' )
< / SCRIPT>
Effect:
Using js to highlight the specified keyword in the article content is like this .. now we have these keywords: beauty, life, and shopping. When these keywords appear in articles, we will highlight them .. the article generates static pages, and these keywords can be updated at any time, so I want to use js to implement it... I don't know how to implement this function? Here for help