[英]Show span on hover over some word and replace on demand
I'm working on a spellchecker plugin for TinyMCE (3.x series). 我正在为TinyMCE(3.x系列)开发拼写检查插件。 When user clicks on plugin to spellcheck I take the editor's content and send it to server, then from server I send the data back with underlining the wrong words and a list of suggestions (which is hidden).
当用户单击插件进行拼写检查时,我将编辑器的内容发送到服务器,然后从服务器将数据发送回去,并在错误的单词下划线并列出建议列表(已隐藏)。 It works fine and on TinyMCE interface I see wrong words with red underline.
它工作正常,在TinyMCE界面上,我看到带有红色下划线的错误单词。
Now I want to show list of suggestions when user hovers (left-click is also fine) over the wrong word so that he can pick the correct word and replace it with wrong word. 现在,我想显示当用户将鼠标悬停在错误的单词上(也可以单击鼠标左键)时的建议列表,以便他可以选择正确的单词并将其替换为错误的单词。 Can anyone guide me how should I proceed on this?
谁能指导我该如何进行?
Textarea content: Fourr guys went to watc movie yesterday.
Textarea内容:
Fourr guys went to watc movie yesterday.
HTML: <p>Fourr guys went to watc movie yesterday.</p>
HTML:
<p>Fourr guys went to watc movie yesterday.</p>
After clicking on plugin the HTML becomes: 单击插件后,HTML变为:
<p>
<span style="color: red; text-decoration: underline;">Fourr</span>
<span class="suggestions" style="display: none;">Fore Furor Furry Fourier Four Farr Fora Fury
Fours Fire Firer Fuhrer Fiori Fourth Dourer Fouler Foyer Fayre Fairer Fr Flour Fort Furrow
Purr</span> guys went to
<span style="color: red; text-decoration: underline;">watc</span>
<span class="suggestions" style="display: none;">WAC Wac Wat watch Watt watt WATS</span>
movie yesterday.
</p>
You can use something like 您可以使用类似
$('span').not('.suggestions').click(function(){
$(this).next('span').toggle();
})
And the you'll need some sort of list from which you can select your option. 并且您将需要某种列表,您可以从中选择选项。 Because from span it will be harder to select, but still possible, look here .
因为从跨度中很难选择,但是仍然有可能,请看这里 。
For changing just save your clicked span in some sort of variable and then replace the text in in with chosen one like 对于更改,只需将单击的跨度保存在某种变量中,然后将文本替换为所选的
var $this;
$('span').not('.suggestions').click(function(){
$this = $(this);
$(this).next('span').toggle();
})
And then after choosing a word 然后选择一个单词
$this.text(yourTextChosenVar)
UPD Added Fiddle with a little bit formated suggestions list. UPD在 Fiddle中添加了一些格式化的建议列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.