我们最近将jQuery升级到了1.9.0,但是它破坏了我们的tipsy插件。它的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);
}
就像一种护身符。:)
发布于 2013-03-18 17:48:41
您需要包含jquery迁移插件,因为您使用的是live:true
,它使用的是removed in jquery 1.9的jquery.live。
为了向后兼容,他们创建了一个可以是downloaded here的migration plugin,并包含迁移插件,以添加对已删除的方法和实用程序的支持。
我会做一些像这样的事情
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);
}
}
发布于 2013-03-18 17:53:09
问题是这个插件仍然使用.live()
来让你在那里使用的方法live
工作,它已经被弃用,并被.on()
所取代。
您应该尝试搜索插件的更新版本,或者尝试自己替换它。
https://stackoverflow.com/questions/15473731
复制相似问题