JavaScript keyword highlighting implements code _javascript tips

Source: Internet
Author: User
<! 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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.