我有Jquery qtip()函数,并且需要在鼠标悬停链接时获取id。我可以使用jquery .load()来获取页面。不能使用下面的代码。有人知道吗?
下面是我的脚本
$(function() {
$(".cabinlink").qtip({
content: $("#loadCabin").load("/mysite ." + $(this).attr('id')),
show: 'mouseover',
hide: 'mouseout',
style: {
width: 780
},
position: {
corner: {
target: 'LeftBottom',
tooltip: 'TopLeft'
}
}
});
});
.cabinlink是mousehover链接
<a id="1" href="javascript:void(0)" class="cabinlink" />
<a id="2" href="javascript:void(0)" class="cabinlink" />
<a id="3" href="javascript:void(0)" class="cabinlink" />
loadCabin是开拓qtip箱
<div id="loadCabin"></div>
修正码股利,能够工作,但需要鼠标两次。第一个mouseover没有结果。有人知道吗?
$(function() {
$(".cabinlink").live('mouseover', function() {
var id = $(this).attr('id');
var url = "/Mysite ." + id;
$(this).qtip({
overwrite: false,
content: $("#loadCabin").load(url),
show: { ready: true, when: false },
hide: 'mouseout',
style: {
width: 780
},
position: {
corner: {
target: 'LeftBottom',
tooltip: 'TopLeft'
}
}
});
});
});
ID不能以数字开头。 – Blender 2013-03-06 01:39:01
我不知道qtip API能够很好地回答你的问题,但我可以告诉你,你没有得到你期望的ID,因为“this”指的是你传递给qtip的选项对象,而不是到被徘徊的元素。我想qtip的一个选项可以让你传递一个回调函数,你可以调用$(this).attr('id')来返回元素的ID。 – 2013-03-06 03:03:47
除此之外,您还需要考虑时间... $(“。cabinlink”)。qtip(...)在页面加载后立即运行,并且只是告诉它使用给定的选项进行初始化。稍后,悬停事件由qtip处理,只有这样,您才会知道哪个元素被悬停。 – 2013-03-06 03:08:37