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

时间:2019-03-03 08:14:02

标签: javascript jquery-plugins

我一直在使用Highlight Text Area plugin,但是在突出显示多个单词时遇到一些问题,请参见下面的代码:

<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>

以下是用粗体突出显示的结果:

交流的nis quis软件和框架Quisque convallis 交流技能充实。 绝妙的凶兆。

如您所见,当我希望获得以下结果时,仅突出显示“通讯”:

沟通 nibh quis 软件和框架 Quisque精通沟通技巧充实。绝妙的凶兆。

1 个答案:

答案 0 :(得分:0)

我没有这个jQuery插件的经验。但是在设置了JSFiddle之后,“摆弄”了一下。看起来插件基于匹配顺序的优先级进行匹配。将您的代码更新到下面,它将可以正常工作。

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