检查是否已将jquery工具工具提示分配给组件 [英] Check if a jquery tools tooltip is already assigned to a component
本文介绍了检查是否已将jquery工具工具提示分配给组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个组件,我首先在 mouseenter
上指定工具提示(对工具提示的懒惰分配)
I have a component to which I assign a tooltip upon first mouseenter
(sort of a lazy assignment of tooltip to component)
我使用惰性方法,因为有许多工具提示组件,我不想为所有这些组件预先分配工具提示。
I use the lazy approach since there are many tooltip'able components and I don't want to pre-assign the tooltips to all of them.
$(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
上创建不工具提示已为此组件创建了c $ c>。
This works just fine. I would like to improve it so the tooltip will not be created on every mouseenter
by checking if the tooltip
was already created for this component.
如何做到这一点?
先谢谢!
推荐答案
你可以尝试这样的事情。
You can try something like this.
$(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
});
这篇关于检查是否已将jquery工具工具提示分配给组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文