The search keywords such as Google and Baidu are highlighted. I have compared several of them, but it is still the best in my hometown. The JavaScript method is very easy to implement. If you want to add it, you can check it out.
1. highlight a single keyword
Code:
<Div id = "TXT">
Use jsArticleHighlight 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 them...
</Div>
<Script language = "JavaScript">
Document. getelementbyid ("TXT "). innerhtml = document. getelementbyid ("TXT ").. innerhtml. replace (/article/GI, "<font color = Red> Article </font> ");
</SCRIPT>
2. Highlight multiple keywords
Code:
<Div id = "TXT">
Use js to highlight the specified keyword in the article content
Well, there are now 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...
</Div>
<Script language = "JavaScript">
Document. getelementbyid ("TXT "). innerhtml = document. getelementbyid ("TXT "). innerhtml. replace (/(Article) | (keyword) | (function)/GI, "<font color = Red> $1 $2 $3 </font> ");
</SCRIPT>
Character meaning
$ (Jscript 5.5 or later)
$ & Specifies the part of stringobj that matches the entire pattern. (Jscript 5.5 or later)
$ 'Specifies the stringobj section before matching by $. (Jscript 5.5 or later)
$ 'Specifies the stringobj part after matching by $. (Jscript 5.5 or later)
$ N indicates the nth child matching captured. Here, n is the first digit in decimal format from 1 to 9. (Jscript 5.5 or later)
$ NN: the NN sub-match captured by NN. NN is a two-digit decimal number from 01 to 99. (Jscript 5.5 or later)
G, global pattern matching
I, case-insensitive matching
Note:
1> If You Want To obtain keywords by passing parameters, you only need to adjust the code as appropriate.
2> pay attention to the matching of the same keywords in your style. For example, if the keyword is "1", your style contains Height = 1, if this is the case, errors will occur. You need to debug these specific errors on your own.