Today do a function: on the page to query the key, so that it highlighted, the implementation code is as follows:
Css:
<style type= "Text/css" > . Highlight { background-color: yellow; } </style>
Javascript:
functionHighlight () {clearselection ();//first, clear the last highlighted content; varSearchText = $.trim ($ (' #txtKeyWord '). Val ());//get the keywords you typed; if(Searchtext.length > 0) { varREGEXP =NewREGEXP (SearchText, ' G ');//Create a regular expression, g means global, if not G, then find the first one will not continue to look down; $(' #dialogue. DHC '). each (function()//traverse the area to be queried; { varHTML = $ ( This). html (); varnewhtml = Html.replace (RegExp, "<span class= ' highlight ' >" + searchtext + ' </span> ');//Replace the Found keyword, plus the highlight attribute; $( This). HTML (newhtml);//updated articles; }); } //Prekeyword = SearchText; } functionClearSelection () {$ (' #dialogue. DHC '). each (function()//Traverse { $( This). Find ('. Highlight '). each (function()//Find all elements of the highlight attribute; { varthishtml = $ ( This). html (); $( This) [0].outerhtml =thishtml; //$ (this). ReplaceWith (thishtml);//remove their attributes; }); }); }
JS implement query keyword, make it highlight