我有一个组件,在第一个mouseenter
上我向其分配了工具提示(对组件的工具提示的惰性分配)
我使用惰性方法,因为有许多可工具提示的组件,而且我不想将工具提示预先分配给所有组件。
$(document).delegate(".tooltipable", "mouseenter", function () {
$(this).tooltip(... options ...);
$(this).tooltip().show(); // The tooltip will not appear on first `mouseenter` so I have to explicitly show it here
});
这样很好。我想对其进行改进,以便通过检查是否已为此组件创建
mouseenter
来在每个tooltip
上都不创建工具提示。那怎么办?
提前致谢!
最佳答案
您可以尝试这样。
$(document).delegate(".tooltipable", "mouseenter", function () {
var $this = $(this);
if(!$this.data("tooltipset")){
$(this).tooltip(... options ...)
.data("tooltipset", true);
}
$(this).tooltip().show(); // The tooltip will not appear on first `mouseenter` so I have to explicitly show it here
});