将文本从跨度内传递到弹出窗口

fak*_*ood 0 javascript jquery

使用jQuery,我正在尝试找出一种方法来将跨区内的单词发送到鼠标悬停时出现的弹出窗口,我不确定如何发送文本.我有弹出窗口,但我无法发送文本.

所以在这个例子中,我想把弹出窗口(class ="popup")简单地说成Hello World.

HTML:

<span class="text" data-id="#text1">Hello World</span>
<div class="popup" id="text1">This should just say Hello World, so this popup is wrong.</div>
Run Code Online (Sandbox Code Playgroud)

JS:

$(document).on("mouseover", ".text", function() {
 var id = $(this).data('id');
 $(id).fadeIn();
}).on('mouseout', '.text', function() {
 var id = $(this).data('id');
 $(id).fadeOut();   
});
Run Code Online (Sandbox Code Playgroud)

CSS:

.text {background-color: red}
.popup {display: none}
Run Code Online (Sandbox Code Playgroud)

小提琴链接

Adi*_*tya 7

这是 使用.text()改变弹出文本的工作小提琴

将此行添加到您的js:

 $(id).text($(this).text());
Run Code Online (Sandbox Code Playgroud)