<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <title> keyword highlighting </title> </pead > <body> <div class= "result" id= "result" > <div> cloud-Habitat community is a professional collection of various types of scripting information site, as far as possible to modify the error to create a quality script class learning site, We for everyone game script resources, source code, software, Asp,php,javascript and other programming materials, is the Web page production, network programming, website Building People's gathering place. </div> <span> to provide the latest network programming, scripting, Web page production, web design, web effects, for webmaster and network programming practitioners to provide learning materials. </span> <div> scripts, VBScript, regular expressions, jquery,dos,bat, batch processing, javascript,photoshop,html,div+css,asp,php,asp.net </div> </div> <script> function Searchhighlight (idval,keyword) {var pucl = document.getElementById (Idval); if ("" = = keyword) return; var temp=pucl.innerhtml; var htmlreg = new RegExp ("\<.*?\>", "I"); var arra = new Array (); Replace the HTML tag for (Var i=0;true;i++) {var m=htmlreg.exec (temp); if (m) {arra[i]=m; } else {break; } temp=temp.replace (M, "{[("+i+"]]} "); Words = Unescape (Keyword.replace (/\+/g, ')). Split (/\s+/); Replace keyword for (w=0;w<words.length;w++) {var r = new RegExp ("() +words[w].replace (/[() {}.+*?^$|\\\[\]]/g," \\$& ") +" ) "," IG "); temp = Temp.replace (R, "<b >$1</b>"); //Restore HTML tags for (var i=0;i<arra.length;i++) {Temp=temp.replace ("{[(" +i+)]} ", Arra[i]); } pucl.innerhtml=temp; } searchhighlight ("Result", "script learning VBScript"); </script> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]