我有如下代码,错误来自instance.content()行。我正在动态加载所有内容并在下面执行所有href标记。 错误是 未捕获的TypeError:instance.content不是函数 我该如何解决这个问题?
ex.find("a[href]").each(function (idx, el) {
var el = $(el);
var url = el.prop("href").substring(4);
el.attr("href", "");
el.addClass("popuplink");
el.tooltipster({
content: 'Loading...',
// 'instance' is basically the tooltip. More details in the "Object-oriented Tooltipster" section.
functionBefore: function (instance, helper) {
var $origin = $(helper.origin);
// we set a variable so the data is only loaded once via Ajax, not every time the tooltip opens
if ($origin.data('loaded') !== true) {
$.get(url, function (data) {
// call the 'content' method to update the content of our tooltip with the returned data
instance.content(data);
// to remember that the data has been loaded
$origin.data('loaded', true);
});
}
}
});
});
答案 0 :(得分:1)
确保您使用的是Tooltipster v4的文件。我没有看到为什么它不能使用你给我们的代码。
答案 1 :(得分:0)
如果其他人遇到V3的这个问题,并希望这适用于V3而不是V4,你可以在这里查看旧文档:
https://web.archive.org/web/20140404021936/http://iamceege.github.io/tooltipster#advanced
基本上他们确实改变了版本之间功能的工作方式,因此令人困惑。这个工作V3的例子可能是:
$('.tooltip').tooltipster({
content: 'Loading...',
functionBefore: function(origin, continueTooltip) {
// we'll make this function asynchronous and allow the tooltip to go ahead and show the loading notification while fetching our data
continueTooltip();
// next, we want to check if our data has already been cached
if (origin.data('ajax') !== 'cached') {
$.ajax({
type: 'POST',
url: 'example.php',
success: function(data) {
// update our tooltip content with our returned data and cache it
origin.tooltipster('content', data).data('ajax', 'cached');
}
});
}
}
});