javascript jQuery hoverIntent:'Uncaught TypeError:无法调用未定义的方法'apply''
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8374494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery hoverIntent: 'Uncaught TypeError: Cannot call method 'apply' of undefined'
提问by Brian
I'm using Brian Cherne's hoverIntent.js
plugin for a project. It's a great plugin but it seems to be broken in jQuery 1.7.1.
我正在hoverIntent.js
为一个项目使用 Brian Cherne 的插件。这是一个很棒的插件,但它似乎在 jQuery 1.7.1 中被破坏了。
I'm trying to debug it but I'm not the most ace javascripter out there. Can anyone tell me what I might need to look for in his code to fix the following error message:
我正在尝试调试它,但我不是那里最优秀的 javascripter。谁能告诉我我可能需要在他的代码中查找什么来修复以下错误消息:
Uncaught TypeError: Cannot call method 'apply' of undefined
Uncaught TypeError: Cannot call method 'apply' of undefined
That's what my Chrome console tells me. I'm just not sure what to change.
这就是我的 Chrome 控制台告诉我的。我只是不确定要改变什么。
There is the following line of code in the plugin which contains apply
in the string
插件中有以下代码行,它包含apply
在字符串中
return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};
return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};
EDIT
编辑
I should post the link to Brian's full commented code. It's here: http://cherne.net/brian/resources/jquery.hoverIntent.js
我应该发布指向 Brian 的完整注释代码的链接。它在这里:http: //cherne.net/brian/resources/jquery.hoverIntent.js
EDIT 2
编辑 2
My script is as follows
我的脚本如下
//#nav-main dropdown effects
$('#nav-main ul li').hoverIntent(function () {
$(this).find('.dropdown').stop(true,true).slideToggle('500');
});
回答by noob
Basically hoverIntent requires two functions or one object.
基本上hoverIntent 需要两个函数或一个对象。
If you put in just one function, it will try to use your function as object and you can't apply a function! So use:
如果您只放入一个函数,它会尝试将您的函数用作对象,而您无法应用函数!所以使用:
$('#nav-main ul li').hoverIntent(function () {
$(this).find('.dropdown').stop(true,true).slideToggle('500');
}, function(){});
回答by ivn
If you are using one object instead of two functions, but without "out" property you would have same error. I did. Adding "out" fixes it in a same way as @noob already answered, just with different syntax, so it might help someone.
如果您使用的是一个对象而不是两个函数,但没有“out”属性,则会出现相同的错误。我做到了。添加“out”以与@noob 已经回答的相同方式修复它,只是使用不同的语法,因此它可能对某人有所帮助。
$('#nav-main ul li').hoverIntent({
over: function () {
$(this).find('.dropdown').stop(true,true).slideToggle('500');
},
out: function() {}
});
回答by byJeevan
I had same problem with 'parallax' plugin.
I changed jQuery librery version to *jquery-1.6.4*
from *jquery-1.10.2*.
And error cleared.
我对“视差”插件有同样的问题。我将 jQuery librery 版本更改为*jquery-1.6.4*
from*jquery-1.10.2*.
并且错误已清除。