I need to highlight the keyword used for search in the blog. So far i managed to used the following script http://www.jquery.info/scripts/SearchHighlight/demo_en.html
but this script doesn't match the exact keywords if one wishes to. It is working as it has been programmed to.
When one select option exact: "exact",
in the function it match's and highlights each word Per id
of search keyword.
How can i modify this script so that it match whole keywords not part of keywords .
In this fiddle example it should only highlight Per id
rather than occurrences of Per
or id
..
Fiddle example: http://jsfiddle.net/gq4hkvgd/
var val2 = "Per id";
var options = {
exact: "exact",
style_name_suffix:false,
keys:val2
}
$('.wrapper').SearchHighlight(options);
Change this line:
var q = options.keys != undefined ? options.keys.toLowerCase().split(/[\s\+\.]+/) : SearchHighlight.decodeURL(ref, SearchHighlight.engines);
To this:
var q = options.keys != undefined ? options.keys.toLowerCase().split(/[\+\.]+/) : SearchHighlight.decodeURL(ref, SearchHighlight.engines);
Now the function doesn't split keywords on white spaces anymore and you will get the desired result.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.