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

Data -id content inside of tooltip

本文关键字:-id 内容 数据 工具提示      更新时间:2023-09-26

我需要从工具提示中的数据内容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"。

我认为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 结构)

小提琴