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!