With JS to achieve, you can optimize the impact of efficiency, the use of server resources issues. The code is as follows:
The following is a reference fragment:
function Xp_highlight ()
{
This. KeyWords = null;
Formatting keywords
This.formatkeyword = function (content, keyword)
{
Keyword = keyword.replace (/(^\s*) | ( \s*$)/g, "");
if (keyword = = ")
return content;
var reg = new RegExp (' (' +keyword+ ') ', ' GI ');
Return Content.replace (Reg, ' <em>$1</em> ');
}
Redraw content Area
This.refreshcontent = function (ContentID)
{
var content = document.getElementById (ContentID). InnerHTML;
for (var i = 0; i < keywords.length i + +)
{
var strkey = keywords[i].tostring ();
var arrkey = Strkey.split (', ');
for (var j = 0; J < Arrkey.length; J + +)
{
var key = Arrkey[j];
Content = This.formatkeyword (content, key);
}
}
document.getElementById (contentid). InnerHTML = content;
}
} |
Call Mode:
The
" Below is a reference fragment:
// keyword definition
&nbs p; var keywords =
[
[' Arisisi, alixixi.com,,web development, really delicious, haha, hee '],
[' dizzy brain swelling, Tired shortness of breath, uninteresting,,, toss, source download, CC, webmaster, programmer, Technology, development '],
[' How, ah, yes, hello ']
];
$ (document). Ready (function () {
var hl = new xp_highlight ();
hl.keywords = keywords; // Here is the definition of the keyword
hl.refreshcontent (' res '); // here is the element ID number to format the content
&NBSP;&NBSP;&NBSP;&NBSP}); |
CSS definition (you can set a variety of styles to support different types of keywords):
-->EM {font-size:small; color: #CC0033; font-style:normal;}