Highlight the use of the search keyword-jquery.highlight.js!

Source: Internet
Author: User

Gossip less, directly look at the need: in an article to find keywords, found after highlighting.

This need can be implemented with JS, can be implemented with jquery, but jquery has ready-made plug-in, pro, you do not have to implement it, just to introduce jquery-hightlight.js

Note: The following body content is so complex just for testing, no other purpose.

< Span style= "font-family: ' Microsoft yahei ', Verdana,sans-serif,simsun; font-size:14px; Line-height:22px ">

<! DOCTYPE html>What is the effect of the implementation? See below:

How about, simple enough! Of course, his function is not only so, hurry up to search the net to see it! Here is the information I refer to:

Http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html

Here's how to use it:

  • Introduction of jquery files and plug-in files in
    <script type=" Text/javascript "src=". /js/jquery-1.4.2.js "></SCRIPT>
    <script type=" Text/javascript "src=". /js/jquery.highlight.js "></SCRIPT>
    <script type=" Text/javascript ">< BR style= "margin-bottom:8px" >function hightlight (str) {
    $ (". Highlight"). Highlight ( STR);
    }
    </SCRIPT>
  • In the body section of the page, join the keyword <body onload= "hightlight (' <%=keywords%> ') from table only son. >
  • CSS style: <style type= "Text/css" >. Highlight{background-color: #FFAEB1;} </style>
  • The details are as follows:
  • Specify the color of the highlighted area in CSS or with jquery:
    . Highlight {background-color: #FFFF88;}
    $ (". Highlight"). CSS ({backgroundcolor: "#FFFF88"});
  • Set the words that need highlighting or trigger highlighting through events. For example:
    $ ("H1"). Highlight ("highlight");
    Highlight "Highligh" in all H1 tags
    $ ("Body P"). Unhighlight ();
    Cancels all the highlights in the body paragraph;
    $ ("P"). Highlight ("JQuery highlight plugin");
    Highlight the entry in the paragraph "jQuery Highlight plugin"
    $ ("P"). Highlight (["JQuery", "highlight", "plugin"]);
    "JQuery", "highlight" and "plugin" in highlighted paragraphs
    $ ("P"). Highlight ("Highlight", {casesensitive:true});
    Highlight the "Highlight" in the paragraph, which is case sensitive.
    $ ("P"). Highlight ("Light", {wordsonly:true});
    The "light" in the highlighted paragraph must be a complete word, and "light" in "highlight" will not be highlighted
    $ ("P"). Highlight ("highlight", {element: ' em ', ClassName: ' Error '});
    Highlight "Hightlight" in the paragraph and assign it a parent tag of Em,class as Error
    $ ("P"). Highlight ("highlight", {element: ' em ', ClassName: ' Error '});
    Highlight "Hightlight" in the paragraph and assign it a parent tag of Em,class as Error
    $ ("Body P"). Highlight ("JQuery", {element: ' A ', ClassName: ' Jquerylink '});
    $ ("Body p a.jquerylink"). attr ({href: ' http://jquery.com '});
    Highlight the "JQuery" in the paragraph and add a link to it.

  • Highlight the use of the search keyword-jquery.highlight.js!

    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.