【发布时间】:2019-09-15 02:02:08
【问题描述】:
我为JQuery UI tooltip widget 编写了以下扩展,它允许工具提示具有从HTMLElement 的html 获取其内容的上下文。但是,我对“标题”属性进行了硬编码,但我想使用options.items 中定义的任何属性。例如,如果他们希望工具提示使用 alt 标记,则扩展会使用 html 内容填充该属性。
我也在寻找正确转义contentIdstring 连接的 jquery ui 方式
$(function() {
(function() {
var cache = {};
$.widget("custom.tooltipContent", $.ui.tooltip, {
_init: function() {
this._super();
this.options.content = function() {
return $(this).attr("title");
};
this.element.attr("title", function() {
var contentId = $(this).attr("data-tooltip-content");
if (!cache[contentId]) {
cache[contentId] = $("[data-tooltip-content-id=" + contentId + "]").remove().html();
}
return cache[contentId];
});
}
});
})();
});
【问题讨论】:
标签: javascript jquery jquery-ui jquery-ui-tooltip