gpt4 book ai didi

jquery - 检查 jquery 工具提示是否已分配给组件

转载 作者:行者123 更新时间:2023-12-01 01:03:19 24 4
gpt4 key购买 nike

我有一个组件,我在第一次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上创建工具提示。

如何才能做到这一点?

提前致谢!

最佳答案

你可以尝试这样的事情。

$(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 - 检查 jquery 工具提示是否已分配给组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8969192/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com