jquery和ajax工具提示不适用于实时加载的内容

jim*_*jim 0 javascript ajax jquery ruby-on-rails

我使用Ruby on Rails和Jquery作为我的库和2个插件,但这应该是一个相当插件独立的问题.

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

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

这些工具提示可以正常处理未加载pageLessly的项目(已经在最初加载的页面上),但不会显示在加载了pageLess的项目上.我的猜测是pageLess提供了一个实时的实时请求来更新页面但是却没有提示工具提示插件,因此没有加载到pageLess返回的任何新链接上.

如何让我的jQuery函数在live load/ajaxed内容的上下文中工作?

Ale*_*lec 9

$('selector').tipsy({
  live: true
});
Run Code Online (Sandbox Code Playgroud)

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

支持直播活动
使用选项{live:true} 支持直播活动.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();
});
Run Code Online (Sandbox Code Playgroud)

如果你的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();
});
Run Code Online (Sandbox Code Playgroud)