相关疑难解决方法(0)

检测文本中单击的单词

我正在构建一个JS脚本,在某个点上,它可以在给定页面上允许用户单击任何单词并将该单词存储在变量中.

我有一个非常难看的解决方案,并使用jQuery进行类解析:我首先解析整个html,拆分每个空间的所有内容" ",并重新附加包含在a中的所有内容<span class="word">word</span>,然后我添加一个带有jQ的事件来检测点击次数这样一个类,并使用$(this).innerHTML我得到点击的单词.

这在很多方面都是缓慢而丑陋的,我希望有人知道另一种方法来实现这一目标.

PS:我可能会考虑将其作为浏览器扩展程序运行,所以如果单纯的JS听起来不可能,并且如果您知道允许的浏览器API,请随时提及它!

一个可能的owrkaround将是让用户突出显示单词而不是单击它,但我真的希望能够通过只需单击即可实现相同的功能!

html javascript parsing

38
推荐指数
5
解决办法
2万
查看次数

得到单词点击段落

我有一个HTML文档,其中包含大约30,000个单词.

我希望能够在用户点击任何单词时执行某些操作.为了简单/概念,我只想alert()说这个词.

例如,在段落中,如果我点击"有"它应该运行alert("have").

我正在使用jQuery.

javascript jquery

16
推荐指数
1
解决办法
6371
查看次数

单击即可获得一个单词

在HTML文档中,如何通过单击获得单词?

例如,如果我有这个:

<div id = "word">
    hello world
</div>
Run Code Online (Sandbox Code Playgroud)

我希望能够点击worddiv中的任何单词并在没有选择的情况下获取它.这可能是使用JQuery吗?

html javascript jquery-plugins

4
推荐指数
1
解决办法
2836
查看次数

如何在用户点击javascript中将单词换入span

我有:简单的html文本块:

<p>
The future of manned space exploration and development of space depends critically on the
creation of a dramatically more proficient propulsion architecture for in-space transportation.
A very persuasive reason for investigating the applicability of nuclear power in rockets is the 
vast energy density gain of nuclear fuel when compared to chemical combustion energy...
</p>
Run Code Online (Sandbox Code Playgroud)

我想:当用户点击它时,将单词换成span.

用户点击了载人字,而不是我应该得到的

<p>
The future of <span class="touched">manned</span> space exploration and development of space depends critically on the
creation …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery

3
推荐指数
1
解决办法
734
查看次数

标签 统计

javascript ×4

html ×3

jquery ×2

jquery-plugins ×1

parsing ×1