0

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

4

1 回答 1

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'); 
                }
            }
        });
    });
});

小提琴

或者更确切地说是这样:(我不明白你的html结构)

小提琴

于 2013-09-25T01:44:09.913 回答