Use JS to highlight the keyword specified by the article content

Source: Internet
Author: User

Use JS to highlight the keyword specified by the article content

is like this. Now there are these keywords: beauty, life, shopping when these keywords appear in the article, highlight it. The article is to generate static pages, and these keywords can be updated at any time, so I would like to use JS to achieve ... Do not know how to achieve such a function AH? hereby asks for help <script language= "JavaScript" > txt.innerhtml = txt.innerHTML.replace (/article/gi, "<font  color=red> article "); </script> multiple keywords with JS to let the article content specified keyword highlighted is this ... Now there are these keywords: beauty, life, shopping when these keywords appear in the article, highlight it. The article is to generate static pages, and these keywords can be updated at any time, so I would like to use JS to achieve ... Do not know how to achieve such a function AH? hereby asks for help <script language= "JavaScript" > txt.innerhtml = Txt.innerHTML.replace (/(article) | ( Keywords) |  (function)/gi, "<font color=red>$1$2$3"); </script>

The code is as follows:

Character meaning
$$ $ (JScript 5.5 or later)
$& Specifies the portion of the stringobj that matches the entire pattern. (JScript 5.5 or later)
$ ' Specifies the stringobj part before the match described by $&. (JScript 5.5 or later)
$ ' Specifies the stringobj part after the match described by $&. (JScript 5.5 or later)
$n the nth substring of the capture, where n is a decimal number from 1 to 9. (JScript 5.5 or later)
$nn the captured nn substring, where nn is the decimal two digits from 01 to 99. (JScript 5.5 or later)
G, global pattern matching
I, case-insensitive matching
Multiple keywords, a good way, I also use

Use JS to highlight the keyword specified by the article content

That is true..

Now there are these keywords: beauty, life, shopping

When these keywords appear in the article, highlight it.

The article is to generate static pages, and these keywords can be updated at any time, so I would like to use JS to achieve ...

Do not know how to achieve such a function AH? hereby ask for help

<table id= "Ttxt" >

Use JS to highlight the keyword specified by the article content

That is true..

Now there are these keywords: beauty, life, shopping

When these keywords appear in the article, highlight it.

The article is to generate static pages, and these keywords can be updated at any time, so I would like to use JS to achieve ...

Do not know how to achieve such a function AH? hereby ask for help

</table>

<script type= "Text/javascript" >

document.getElementById ("Bdshell_js"). src = "http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + new Date (). GetHours ();

</script>

<script type= "Text/javascript" src= "http://v1.ujian.cc/code/ujian.js?uid=1599009" ></script>

<script type= "Text/javascript" id= uyscript "src=" Http://v1.uyan.cc/js/iframe.js? uyuserid=1599004 "async=" "></script>

<script>

(function () {

var cx = ' partner-pub-6079350801821541:7402284747 ';

var GCSE = document.createelement (' script ');

Gcse.type = ' Text/javascript ';

Gcse.async = true;

GCSE.SRC = (Document.location.protocol = = ' https: '? ' https: ': ' http: ') +

'//www.google.com/cse/cse.js?cx= ' + cx;

var s = document.getelementsbytagname (' script ') [0];

S.parentnode.insertbefore (GCSE, S);

})();

</script>

</body>

Why do we have to be limited to the substitution of HTML, from the text object is not more convenient to start? &lt;pre&gt; use JS to let the content specified in the article highlighted the keyword is this ... Now there are these keywords: beauty, life, shopping when these keywords appear in the article, highlight it. The article is to generate static pages, and these keywords can be updated at any time, so I would like to use JS to achieve ... Do not know how to achieve such a function AH? hereby ask for help &lt;/pre&gt; &lt;script language= "JavaScript" &gt; Function highlight (key) {var key = Key.split (      '|');          for (var i=0 i&lt;key.length; i++) {var rng = Document.body.createTextRange ();      while (Rng.findtext (Key[i])) rng.pastehtml (Rng.text.fontcolor (' Red ')); } Highlight (' article | key | function ') &lt;/script&gt; &lt;pre&gt; is like this. Now there are these keywords: beauty, life, shopping when these keywords appear in the article, highlight it. The article is to generate static pages, and these keywords can be updated at any time, so I would like to use JS to achieve ... Do not know how to achieve such a function AH? hereby ask for help &lt;pre&gt;

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.