In the tutorial www.bkjia.com, many friends may see links to some keywords in some articles, which are very similar to internal advertisements. It is very easy to achieve this effect, today, www.bkjia.com sorted out this function and looked at the following functions:
Copy to ClipboardReference: [www.bkjia.com] function hkwords (keyWordArr, textElement)
{
Var article_text = textElement. innerHTML;
Var RegexpKeyWordString = "";
For (var I = 0; I <keyWordArr. length; I ++)
{
RegexpKeyWordString + = keyWordArr [I] + "|"
}
RegexpKeyWordString = RegexpKeyWordString. replace (// | $/, ""). replace (// \\/ g ,"\\\\");
Var regExpObj = eval ("/" + RegexpKeyWordString + "/g ");
Article_text = article_text.replace (regExpObj, function (kword) {return "<a href = 'HTTP: // www.bkjia.com 'target = '_ blank' class = 'akword'> "+ kword +" </a> ";})
TextElement. innerHTML = article_text
}
Help house note: keyWordArr is an array for storing keywords, and textElement is the content to be processed.