在 JQuery 中突出显示重叠文本
我有这个纯 HTML:
"Many things are in my room: a bed, a desk, and a computer."
和这些短语:
"things are"
"are in my room"
"room: a bed"
在 JQuery 中,是否有某种方法可以循环遍历短语列表,并突出显示文本中出现的短语,并用颜色或边框等来划分重叠部分?
我知道有简单的荧光笔,但这并不能解决问题。也许是有重叠不透明度的东西?谢谢!
I've got this plain HTML:
"Many things are in my room: a bed, a desk, and a computer."
And these phrases:
"things are"
"are in my room"
"room: a bed"
In JQuery, is there some way to loop through the phrase list, and highlight the phrases as they appear in the text, and have the overlap delineated by color, or border, etc?
I know there are simple highlighters but that won't do the trick. Maybe something with overlaying opacities? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不幸的是,我所知道的荧光笔都不能满足您的要求,特别是因为 HTML 只是纯文本。
移动高级荧光笔只会将三个独立的块压缩成一个整体并突出显示所有内容。
如果您确实需要做类似的事情,您可以获取每个块并比较它是否有重叠。然后,如果有的话,从每个块中删除重叠部分并创建一个新的“重叠”突出显示(如果有意义的话)。
Unfortunately none of the highlighters I know can do what you are asking, specially because the HTML is simply plain text.
Move advanced highlighters would simply condense the three separated chunks into a single unity and highlight everything.
If you really need to do something like that you could get each chunk and compare if it has any overlapping. Then if it has, remove the overlapping part from each chunk and create a new "overlapped" highlight, if that makes sense.
有一个名为 anotaterjs 的很棒的 js 东西,它可能能够做到这一点。它支持嵌套突出显示,并允许您向突出显示添加注释。
There is this great js thinggy called anotaterjs that's probably able to do just that. It supports nested highlightings and allows you to add a note to your highlighting.
我必须实现类似的目标,并且我为此付出了很多努力。
我找到了类似这样的解决方案。
http://jsfiddle.net/pw9kkg2x/34/
I had to achieve something similar and I worked on it a lot.
I found a solution something like this.
http://jsfiddle.net/pw9kkg2x/34/