[英]jquery and ajax tooltips don't work on live loaded content
我正在使用Ruby on Rails和Jquery作为我的库和2个插件,但这应该是一个与插件无关的问题。
我正在使用jquery.pageLess插件,该插件对内置在rails中的分页进行ajax调用,以便在您滚动到底部时将新项目加载到页面上(类似于新的google images布局)。
但是,我也使用Tipsy插件将工具提示添加到正在加载的链接的图像部分。
这些工具提示在未pageLessly加载的项目(已经在原始加载的页面上)上正常工作,但是在pageLess加载的项目上不显示。 我的猜测是pageLess提出了实时实时更新页面的请求,但是没有提示性的工具提示插件,因此没有加载到pageLess返回的任何新链接上。
如何使jQuery函数在实时加载/邻接内容的上下文中工作?
$('selector').tipsy({
live: true
});
http://onehackoranother.com/projects/jquery/tipsy/
支持直播活动
使用选项{live:true}支持实时事件。 jQuery≥1.4.1是必需的,实时工具提示不支持手动触发。
编辑
另一种方法是在创建新元素后将Tips绑定到它们。 例:
$('selector').tipsy();
// post, get, ajax, etc
$.post(..., function(data) {
// in the return function, first create the new elements
...
// call on the tipsy method again
// the selector will now also match the newly created elements
$('selector').tipsy();
});
如果tipsy
方法中包含很多变量,并且不想重复它,则创建单独的函数可能会更容易。 例:
// create the function
function setupTipsy() {
$('selector').tipsy({
html: true,
gravity: 'w',
etc..
});
}
// call on the function when the document has been loaded
setupTipsy();
// post, get, ajax, etc
$.post(..., function(data) {
// in the return function, first create the new elements
...
// call on the same function again
setupTipsy();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.