工具提示中的数据-id内容

时间:2013-09-25 01:39:32

标签: javascript

我需要从工具提示中的data-content-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”。

1 个答案:

答案 0 :(得分: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

相关问题