2013-09-25 18 views
0

我需要從工具提示內的數據內容ID獲取內容。出於某種原因,它不會抓住內容並將其拉入內部。工具提示中的數據-id內容

下面是代碼:

// Create the tooltips only when document ready 
$(document).ready(function() 
{ 
/// Grab all elements with the class "hasTooltip" 
$('.hasTooltip').each(function() { // Notice the .each() loop, discussed below 
$(this).qtip({ 
    content: { 
     text: $('#tooltip-content-' + $(this).find('[data-contentid]').data('contentid')) // Grab content using data-content-id attribite value 
    } 
}); 
}); 
}); 

爲了更好地理解這裏是一個小提琴:http://jsfiddle.net/L6yq3/465/在這裏你可以看到,我不能得到提示裏面的「CONTENTEXAMPLE」。

+0

這將是jQuery,而不是簡單的[javascript]如標籤所示...您可以在大多數瀏覽器上設置somenode.title =「您的工具提示文本」(或標題=「您的工具提示文本」在html標籤中),以便於在大多數瀏覽器上獲得「工具提示」檢索沒有jquery – technosaurus

回答

0

我覺得text接受功能,所以嘗試:

// Create the tooltips only when document ready 
$(document).ready(function() { 
    /// Grab all elements with the class "hasTooltip" 
    $('.hasTooltip').each(function() { // Notice the .each() loop, discussed below 
     $(this).qtip({ 
      content: { 
       text: function() { 
        return $(this).next('[data-contentid]').data('contentid'); 
       } 
      } 
     }); 
    }); 
}); 

Fiddle

或者更確切地說,是這樣的:(我不明白你的HTML結構)

Fiddle

+0

我試過這個,現在甚至沒有顯示空的工具提示。 http://jsfiddle.net/L6yq3/469/ – user2800148

+0

@ user2800148只是在那刪除一個slas。這是一個錯字http://jsfiddle.net/eEgRp/ – PSL

+0

我認爲問題出現在你寫的html結構中。我想在工具提示裏面有「CONTENTEXAMPLE」。爲此,我設置了

CONTENTEXAMPLE
。你的第二個解決方案到目前爲止工作,但爲什麼它不與數據contentid =「測試」? – user2800148