如何突出jquery中的每个单词,以便为每个单词提供定义? [英] How can I highlight every single word in jquery so that I can provide a definition for each word?

查看:161
本文介绍了如何突出jquery中的每个单词,以便为每个单词提供定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要做的是允许用户滚动网页上的任何单词,当鼠标翻过该单词时,它会突出显示(我知道我可以使用悬停)。但是我不知道如何从段落中选择单个单词。最终目标是允许用户点击单词并在单词上显示定义,但我想我可以在将单词悬停在单个单词上时将其弄清楚。

What I am trying to do is allow the user to scroll over any word on a web page and when the mouse goes over the word it is highlighted (I know I can use hover for that). However I do not know how to select individual words, from the paragraph. The ultimate goal is to allow the user to click on the word and a definition appears over the word, but I think I can figure that out once I can hover over individual words.

推荐答案

在Javascript中没有办法做到这一点,你可以与之交互的最小的东西,一般来说,是一个DOM元素。所以你可以在技术上将每个单词包装在< span> 中,但这似乎是严重的过度杀伤,并且可能也会产生巨大的性能影响。

There is no way in Javascript to do that, the smallest thing you can interact with, in general, is a DOM element. So you could technically wrap each word inside a <span>, but that would seem to be seriously overkill and probably have a huge performance impact as well.

相反,大多数网站提供此功能的是,无论何时选择文本,他们都会执行悬停弹出窗口(查看此问题以获取当前选择的一些代码

Instead, what most sites do, that provide this functionality, is they do the hover popup thing whenever you select text (see this question for some code to get the current selection).

就我个人而言,我觉得它真的很烦人(例如,nytimes.com就是这样),但也许只是我...

Personally, I find it really irritating (nytimes.com does it like that, for example), but maybe that's just me...

这篇关于如何突出jquery中的每个单词,以便为每个单词提供定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆