2010-10-08 48 views
0

我使用Ruby on Rails和Jquery作为我的库和2个插件,但这应该是一个相当独立的插件独立问题。jquery和ajax工具提示不适用于活动加载的内容

我正在使用jquery.pageLess插件,它会对内置到rails中的分页进行ajax调用,以便在滚动到底部时将新项目加载到页面上(很像新的Google图像布局) 。

但是,我也使用插件来将工具提示添加到正在加载的链接的图像部分。

这些工具提示可以在没有加载页面的项目上正常工作(它们已经在最初加载的页面上),但不会显示在加载页面的项目上。我的猜测是,pageLess会生成一个实时的实时请求来更新页面,但醉人的tooltip插件不会,因此不会加载到由pageLess返回的任何新链接上。

如何让我的jQuery函数在活动加载/ ajaxed内容的上下文中工作? {:真正的活}

回答

9
$('selector').tipsy({ 
    live: true 
});

http://onehackoranother.com/projects/jquery/tipsy/

支持直播活动
的现场活动并使用选项的支持。 jQuery≥1.4.1是必需的,而实时工具提示不支持手动触发。

编辑
另一种方法是创建完毕后,他们结合醉意的新元素。例如:

$('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(); 
});
+0

doh!谢谢,但如果你正在使用一个没有这种选项的插件。那么你怎么去做呢? – jim 2010-10-08 17:12:56

+0

添加到答案。 – Alec 2010-10-08 18:32:01

相关问题