【问题标题】:jQuery Tooltip plugin errorjQuery Tooltip 插件错误
【发布时间】:2011-01-15 08:36:09
【问题描述】:

我已经编写了这段代码来将“jQuery Tooltip 插件”应用于 ajax 加载的元素。

我的意思是我想在鼠标悬停时显示工具提示的行是由 ajax 加载到页面中的。 这是代码:

$("[id^=pane]").delegate("[id^=comm]","mouseover",function() {

   $(this).tooltip({

      // each trashcan image works as a trigger
      tip: "#tooltip",
      // custom positioning
      position: "center right",
      // move tooltip a little bit to the right
      offset: [0, 15],
      // there is no delay when the mouse is moved away from the trigger
      delay: 0
  }).dynamic({ bottom: { direction: "down", bounce: true } });

});

鼠标悬停时显示工具提示但firebug报告此错误:

"$(this).tooltip({tip: "#tooltip", position: "center right", offset: [0, 15], delay: 0}).dynamic 不是函数"

是因为使用了$(this)吗???

【问题讨论】:

    标签: jquery-plugins jquery tooltip


    【解决方案1】:

    问题是你还没有加载dynamic 函数。来自the jQuery tools documentation

    动态插件和幻灯片效果不包含在标准 jQuery 工具分发中。您必须下载 custom combination 才能包含这些效果。


    此外,您不需要您的delegate 电话。每次鼠标悬停时,您都在重做 tooltip 创建。你只需要做一次;该插件将在内部处理事件。

    $("[id^=pane] [id^=comm]").tooltip({/*...*/})
           .dynamic({/*...*/});
    

    这会选择所有 id 以 comm 开头的元素,它们是 id 以 pane 开头的元素的子元素。请注意,为所有这些元素添加适当的类会显着加快您的选择速度。

    【讨论】:

    • 谢谢,但动态包含在我的 jquery 工具文件中。除了从其网站的工具提示之外,我还选择了它。我使用委托,因为我使用 ajax 添加我的元素。
    • delegate 不是动态添加元素的万能解决方案。每次您将鼠标悬停在一个元素上时,您都在调用tooltip 函数,这在计算上必然是昂贵的。其次,很难通过猜测来调试问题。如果您可以提供代码的(非)工作示例,那将使事情变得容易 16.34 倍。
    【解决方案2】:

    现在已经解决了,我在google上搜索了更多,找到了解决方案。

    这里是:

    $("[id^=pane]").delegate("[id^=comm]:not(.hastooltip)","mouseover",function() {
        $(this).addClass("hastooltip").tooltip({
            tip: "#tooltip",
            position: "bottom center",
            offset: [-10, 0],
            delay: 0
        }).dynamic({ bottom: { direction: "down", bounce: true } }).mouseover();
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-05
      • 1970-01-01
      • 1970-01-01
      • 2015-02-17
      • 1970-01-01
      相关资源
      最近更新 更多