问题
I have a monkey script to highlight parts of a site using mark.js with jquery. I have a value in the array called "New York". I would like it so when it finds the word "new" or "york" individually, it doesn't highlight it, just the string "new york" Code:
var instance = new Mark(document.querySelector("body"));
instance.mark(["Total%20Loss%20Reported", "NY", "NJ", "stolen", "Canada", "frame%20damage", "moderate", "New%20Jersey", "New%20York", "structural", "accident", "damage", "damaged"], {
"accuracy": "exactly"
});
$('mark').css({'background':'transparent' , 'color':'red'});
Edit: I tried the %20 for spaces instead of a space, and it didn't work, also tried / /g
回答1:
The documentation says to use separateWordSearch
option:
instance.mark(["New York"], {
accuracy: "exactly",
separateWordSearch: false,
});
回答2:
You have to disable the option separateWordSearch
. Set it to false and it will highlight only "new york" and not single words of it. Btw.: Don't use "%20" for spaces.
Have a look at the documentation for more information.
来源:https://stackoverflow.com/questions/38622653/mark-js-highlighting-specific-words