【问题标题】:Check if a jquery tools tooltip is already assigned to a component检查是否已将 jquery 工具工具提示分配给组件
【发布时间】:2012-01-23 09:07:10
【问题描述】:

我有一个组件,我在第一次 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
});

这很好用。我想对其进行改进,以便通过检查是否已为此组件创建 tooltip不会在每个 mouseenter 上创建工具提示。

如何做到这一点?

提前致谢!

【问题讨论】:

    标签: jquery jquery-tools jquery-tooltip


    【解决方案1】:

    你可以试试这样的。

    $(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
    });
    

    【讨论】:

    • 谢谢,使用类似的方法来验证工具提示是否已经初始化,以便我可以在需要时安全地销毁它。
    猜你喜欢
    • 2021-12-04
    • 2013-09-20
    • 1970-01-01
    • 2010-10-30
    • 2013-09-19
    • 2011-04-21
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    相关资源
    最近更新 更多