2010-10-08 74 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