2012-01-22 19 views
1

我有像這樣創建與基於計算的URI PARAMS AJAX內容的qtip

$("#permalink").qtip({ 
    content: { 
     text: "Loading...", 
     ajax: { 
      url: "http://server/app", 
      type: "GET", 
      data: { 
       "uri": $(this).attr("href") 
      }, 
      success: function(data, status) { 
       this.set(data); 
      } 
     } 
    } 
}) 
.click(function(event) { 
    event.preventDefault(); 
}); 

中的HREF被一些動態更新的,像這樣

<a href="" id="permalink">permalink</a> 

到我所結合的qtip2一個鏈路其他代碼(實際上,OpenLayers中的永久鏈接控件)。如果我在沒有qtip的情況下點擊永久鏈接,我會得到正確的href。但是,使用qtip時,$(this).attr(「href」)不會得到任何結果。它沒有設置。我怎樣才能讓qtip接收動態計算的href?

回答

2

使用「each()」。你應該有正確的範圍$(this)然後...

$("#permalink").each(function() { 
    $(this).qtip({ 
     content: { 
      text: "Loading...", 
      ajax: { 
       url: "http://server/app", 
       type: "GET", 
       data: { 
        "uri": $(this).attr("href") 
       }, 
       success: function(data, status) { 
        this.set('content.text', data); 
       } 
      } 
     } 
    }) 
}) 
.click(function(event) { 
    event.preventDefault(); 
}); 
0

上述解決方案工作正常,但有以下更改。 我已經驗證了這個最新的穩定版本(v2.0.1)。

而不是this.set(data); 使用 this.set('content.text', data);