我不确定是什么导致了这种情况,但我使用了线索提示并将其绑定到一个实时事件(单击或鼠标输入),但在每种情况下,线索提示直到单击或悬停事件之后才会触发。对于ajax加载的内容,我使用了live event,但对于非Ajax加载的内容,我也遇到了这个问题。我不确定为什么会发生这种情况--有人能看到我哪里出了问题吗?非常感谢。
$("a.jTip").live("click", function(){
$('a.jTip').cluetip({
attribute: 'href',
cluetipClass: 'jtip',
arrows: true,
activation: 'click',
ajaxCache: false,
dropShadow: true,
sticky: true,
mouseOutClose: false,
closePosition: 'title'
})
return false;
});发布于 2010-04-19 22:17:42
这是因为你要在第一个事件之后才能设置它。换句话说,您正在处理事件(显然),并且您在处理程序中设置了工具。该特定事件不会触发线索提示代码。
相反,您可以考虑确保动态添加内容的代码始终直接调用“线索提示”设置,或者研究"LiveQuery“插件,以便在DOM更改时执行”自动“工作。就我个人而言,我会选择前一种方法,但显然很多人使用LiveQuery的效果都很好。
发布于 2010-04-19 22:17:49
您仍然可以使用livequery() plugin来执行此操作,如下所示:
$('a.jTip').livequery(function() {
$(this).cluetip({
attribute: 'href',
cluetipClass: 'jtip',
arrows: true,
activation: 'click',
ajaxCache: false,
dropShadow: true,
sticky: true,
mouseOutClose: false,
closePosition: 'title'
});
});.live()并没有完全取代.livequery(),它的行为方式有所不同。如果你仍然想寻找与选择器匹配的当前元素和新元素,将.livequery()或binding作为ajax回调的一部分(例如,在你像$('a.jTip', data)一样成功的时候)是最好的途径。
发布于 2010-04-19 22:17:07
因为直到第一次单击之后,线索提示才被初始化。
尝试:
$("a.jTip").live("mousedown", function(event){
$('a.jTip').cluetip({
attribute: 'href',
cluetipClass: 'jtip',
arrows: true,
activation: 'click',
ajaxCache: false,
dropShadow: true,
sticky: true,
mouseOutClose: false,
closePosition: 'title'
})
event.preventDefault();
});尽管cluetip将被多次初始化,但下面的示例如何:
$("a.jTip").live("mousedown", function(event){
var self = $(this);
if (!self.data('cluetip-initd')) {
self.cluetip({
attribute: 'href',
cluetipClass: 'jtip',
arrows: true,
activation: 'click',
ajaxCache: false,
dropShadow: true,
sticky: true,
mouseOutClose: false,
closePosition: 'title'
}).data('cluetip-initd', true);
};
event.preventDefault();
});https://stackoverflow.com/questions/2668039
复制相似问题