【问题标题】:tipsy live does not work with jQuery 1.9.0Tipsy live 不适用于 jQuery 1.9.0
【发布时间】:2013-03-18 09:47:14
【问题描述】:

我们最近将 jQuery 升级到 1.9.0,但它破坏了我们的醉意插件。它的live 功能现在会导致错误。

$('.tooltip, abbr').tipsy({
    live: true
});

TypeError: this[binder] is not a function

对此有任何修复或补丁吗?谷歌搜索并没有带来任何有用的东西。


更新:

感谢您的回答。我决定尝试自己解决这个问题,因为我找不到任何补丁。

经过检查,错误似乎很容易追踪。 Tipsy 插件可以很容易地被修补以使用on 功能而不是已弃用的live 功能。在tipsy插件中,我替换了以下代码:

if (options.trigger != 'manual') {
    var binder = options.live ? 'live' : 'bind',
        eventIn = options.trigger == 'hover' ? 'mouseenter' : 'focus',
        eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur';
    this[binder](eventIn, enter)[binder](eventOut, leave);
}

与:

if (options.trigger != 'manual') {
    var eventIn = options.trigger == 'hover' ? 'mouseenter' : 'focus',
        eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur';
    if (options.live)
        $(document).on(eventIn, this.selector, enter).on(eventOut, this.selector, leave);
    else
        this.bind(eventIn, enter).bind(eventOut, leave);
}

像魅力一样工作。 :)

【问题讨论】:

  • 在这里搜索jquery plugin conflict
  • 好帖子!你从哪里得到this.selector
  • @RichPeck this.selector 是底层 jQuery 对象的属性。
  • 奇怪的反应,直到我用 $('body') 替换 $(document),现在,就像一个魅力。 :)
  • 谢谢!正是我正在寻找的:)

标签: jquery jquery-plugins tooltip live tipsy


【解决方案1】:

您需要包含 jquery 迁移插件,因为您使用的是live:true,它使用了jquery.live,即removed in jquery 1.9

为了向后兼容,他们创建了一个migration plugin,可以是downloaded here,并包含迁移插件以添加对已删除方法和实用程序的支持。

我会做类似的事情

if (options.trigger != 'manual') {
    var eventIn  = options.trigger == 'hover' ? 'mouseenter' : 'focus',
        eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur';
    if(options.live){
      $(this.context).on(eventIn, this.selector, enter).on(eventOut, this.selector, leave);
    } else {
      this.on(eventIn, enter).on(eventOut, leave);
    }
}

【讨论】:

  • 我不想在这个项目中使用 jQuery 迁移插件。我们打算不使用任何已弃用的功能。
  • 那你能不能换tipsy插件,如果不能,那我觉得你有问题
  • 这是一个很好的解决方案,我在 github 上看到了很多关于这个特定问题的问题。我想知道为什么作者不接受任何拉取请求?
  • 这个答案比更新后的问题的解决方案更好,因为它使用$(this.context) 而不是$(document) 来委托事件。
【解决方案2】:

问题是这个插件仍然使用.live()来让你在那里使用的方法live工作,它已被弃用并已被.on()取代。

您应该尝试搜索插件的更新版本或尝试自行替换。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-12
    • 1970-01-01
    • 2010-12-07
    • 1970-01-01
    • 1970-01-01
    • 2016-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多