检查是否已将jquery工具工具提示分配给组件
我有一个组件,我在第一个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 });