3

我有一个组件,我首先为其分配了一个工具提示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已为此组件创建工具提示来创建工具提示。

怎么可能呢?

提前致谢!

4

1 回答 1

5

你可以尝试这样的事情。

$(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
});
于 2012-01-23T09:16:01.397 回答