我有以下要素:交换实现文本
<div contenteditable="true" id="write">
<div class="tooltip">
<span>test</span> <!--text to be written in text area-->
<span class="tooltiptext"> <!--holds words to be displayed on hover-->
<span class="popUpWord">hello</span>
<br>
<span class="popUpWord">dog</span>
</span>
</div>
<div class="tooltip">
<span>test</span>
<span class="tooltiptext">
<span class="popUpWord">hello</span>
<br>
<span class="popUpWord">test</span>
</span>
</div>
</div>
这些基本显示弹出类似于下面 - http://www.w3schools.com/css/tryit.asp?filename=trycss_tooltip
在具有” .tooltop元素的悬停事件'类(在弹出区域内显示单词),我想将弹出区域中悬停的单词与几秒钟后在文本区域中显示的单词进行交换。
我做了以下功能:
//--choosing word from pop-up list--//
$(document).on("mouseover", ".popUpWord", function(e)
{
if(!timeoutId)
{
timeoutId=window.setTimeout(function()
{
timeoutId=null;
e.currentTarget.innerHTML = e.fromElement.parentElement.parentElement.childNodes[0].childNodes[0].innerText;
/*not working*/ e.fromElement.parentElement.parentElement.childNodes[0].childNodes[0].innerHTML = e.currentTarget.innerHTML; //Although the elements I want to swap are referred to correctly,the element's text is not changing. (Tried using innerText)
},1500);
}
}).on('mouseout', '.popUpWord', function(e)
{
if(timeoutId)
{
window.clearTimeout(timeoutId);
timeoutId=null;
}
});
然而,行标not working
- 元素的文本没有改变。它正在被正确引用。
任何帮助,非常感谢。
感谢
这部分工作。我将在弹出区域中有多个单词。如何将悬停的单词(在弹出区域中)与文本区域中的相应单词交换?目前,文本区域中的第一个单词总是在变化。 – Techs