简体   繁体   English

如何使用“突出显示文本区域”插件突出显示多个单词

[英]How to highlight multiple words with the Highlight Text Area plugin

I've been using the Highlight Text Area plugin , but I'm having some problems to highlight multiple words, see code below: 我一直在使用“ 突出显示文本区域”插件 ,但是在突出显示多个单词时遇到一些问题,请参见下面的代码:

<textarea cols="50" rows="5">communications nibh quis software & framework Quisque convallis communication skills vulputate. 
auctor blandit luctus.</textarea>

<script>
 $('textarea').highlightTextarea({
  words: ['software & framework', 'communication','communications','communication skills'],

});
</script>

Here are the results highlighted in bold: 以下是以粗体突出显示的结果:

communication s nibh quis software & framework Quisque convallis communication skills vulputate. 交流能力quis软件和框架Quisque精通交流技巧。 auctor blandit luctus. 奥古斯特·布兰迪特·卢克图斯。

As you can see only "communication" is highlighted while I'd like to have the following results: 如您所见,当我希望获得以下结果时,仅突出显示“通信”:

communications nibh quis software & framework Quisque convallis communication skills vulputate. 交流技巧软件和框架 Quisque精通交流技巧 auctor blandit luctus. 奥古斯特·布兰迪特·卢克图斯。

I have no experience with this jQuery plugin. 我没有这个jQuery插件的经验。 But after setting up a JSFiddle , and "fiddling" around. 但是在设置了JSFiddle之后 ,“摆弄”了一下。 Looks like the plugin matches based on priority of the order of the matches. 看起来插件基于匹配顺序的优先级进行匹配。 Update your code to the below and it will work. 将您的代码更新为以下代码,它将起作用。

$('textarea').highlightTextarea({
    words: ['communication skills', 'communications', 'software & framework', 'communication'],
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM