mark.js突出显示特定单词 [英] mark.js Highlighting specific words
本文介绍了mark.js突出显示特定单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个猴子脚本,用于将mark.js与jquery一起突出显示网站的某些部分.我在名为"New York"的数组中有一个值.我希望这样,当它单独找到"new"或"york"一词时,它不会突出显示,而只是字符串"new york" 代码:
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'});
我尝试用%20代替空格,但它不起作用,也尝试了//g
I tried the %20 for spaces instead of a space, and it didn't work, also tried / /g
推荐答案
文档说要使用separateWordSearch
选项:
instance.mark(["New York"], {
accuracy: "exactly",
separateWordSearch: false,
});
这篇关于mark.js突出显示特定单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文