当用户将鼠标悬停在特定的文本字符串上时,我正在使用jquery hovercard 插件从使用 ajax 的文本文件中提取文本 - 这一切都很好,(下面的代码)。
现在我想做的是在文本文件中有许多不同的 div(如下所示),并根据悬停在哪个文本字符串上拉入相关的 div。这对 Jquery/Ajax 是否可行,如果可以,请问您是如何做到的?
//文本文件内容
<div id="John_Resig">
<div class="contact">John Resig</div>
<p><strong>Testing testing testing!</strong></p>
<p>And on another line of text : )</p>
</div>
<div id="Tim_Berners_Lee">
<div class="contact">Tim Berners-Lee</div>
<p><strong>Testing testing testing!</strong></p>
<p>And on another line of text : )</p>
</div>
//jQuery/Ajax 代码
$(document).ready(function () {
var hoverHTMLDemoAjax = '<div class="demo-cb-tweets"></div>';
$(".demo-ajax").hovercard({
detailsHTML: hoverHTMLDemoAjax,
width: 350,
delay: 500,
cardImgSrc: 'http://ejohn.org/files/short.sm.jpg',
onHoverIn: function () {
$.ajax({
url : "helloworld.txt",
type: 'GET',
dataType: "text",
beforeSend: function () {
$(".demo-cb-tweets").prepend('<p class="loading-text">Loading latest tweets...</p>');
},
success: function (data) {
$(".demo-cb-tweets").empty();
$(".demo-cb-tweets").html(data);
},
complete: function () {
$('.loading-text').remove();
}
});
}
});
});