Javascript jQuery 问题 - #<an Object> 没有方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2988485/
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 issue - #<an Object> has no method
提问by Shaun
I've tried a veriety of jQuery plugins recently and I keep getting this error …
我最近尝试了很多 jQuery 插件,但我不断收到这个错误......

(source: shaunbellis.co.uk)

(来源:shaunbellis.co.uk)
… regardless of what plugin I try to use.
...无论我尝试使用什么插件。
I've checked the links to the JS files which are all there and working fine. I'm using Drupal if that makes any difference.
我已经检查了指向 JS 文件的链接,这些文件都在那里并且工作正常。如果这有什么不同,我正在使用 Drupal。
I've run the plugins away from the main site to demonstrate that they are working and that I am doing things right with 100% success.
我已经在远离主站点的地方运行插件,以证明它们正在工作,并且我正在做的事情 100% 成功。
Any ideas?
有任何想法吗?
Update:
更新:
My jQuery file called in the footer:
我的 jQuery 文件在页脚中调用:
$(document).ready(function() {
$('#footer_holder').hide();
// Fancy Box
$("a.fancybox").fancybox({
'hideOnContentClick': true,
'titlePosition' : 'over',
'transitionIn' : 'elastic',
'transitionOut' : 'elastic',
'speedIn' : 600,
'speedOut' : 200,
'overlayShow' : false,
});
$("#homepage_slider").easySlider({
auto: true,
continuous: true,
});
});
});
*note - fancy box works fine (unless the easySlider code is above it). jQuery is sorted out by Drupal. I'm running version 1.4
*注意 - 花哨的盒子工作正常(除非 easySlider 代码在它上面)。jQuery 由 Drupal 整理。我正在运行 1.4 版
采纳答案by Shaun
Ignore me. I'm sorry everyone. I'd mistyped the url of the script. Thanks to Simon Ainley for the prod in the right direction.
不理我。对不起大家。我打错了脚本的网址。感谢西蒙·安利 (Simon Ainley) 在正确方向上的推动。
Sorry again. Thanks.
再次抱歉。谢谢。
回答by Stephen Saucier
This problem can also arise if you include jQuery more than once.
如果多次包含 jQuery,也会出现此问题。
回答by Michael Wolf
I had this problem, or one that looked superficially similar, yesterday. It turned out that I wasn't being careful when mixing jQuery and prototype. I found several solutions at http://docs.jquery.com/Using_jQuery_with_Other_Libraries. I opted for
昨天我遇到了这个问题,或者表面上看起来很相似的问题。事实证明,我在混合 jQuery 和原型时没有小心。我在http://docs.jquery.com/Using_jQuery_with_Other_Libraries找到了几个解决方案。我选择了
var $j = jQuery.noConflict();
but there are other reasonable options described there.
但那里描述了其他合理的选择。
回答by Sablefoste
For anyone else arriving at this question:
对于遇到这个问题的其他人:
I was performing the most simple jQuery, trying to hide an element:
我正在执行最简单的 jQuery,试图隐藏一个元素:
('#fileselection').hide();
and I was getting the same type of error, "Uncaught TypeError: Object #fileselection has no method 'hide'
并且我收到了相同类型的错误,“未捕获的类型错误:对象 #fileselection 没有方法‘隐藏’
Of course, now it is obvious, but I just left off the jQuery indicator '$'. The code should have been:
当然,现在很明显了,但我只是省略了 jQuery 指示符“$”。代码应该是:
$('#fileselection').hide();
This fixes the no-brainer problem. I hope this helps someone save a few minutes debugging!
这解决了无脑问题。我希望这可以帮助某人节省几分钟的调试时间!
回答by Scott H
This problem may also come up if you include different versions of jQuery.
如果您包含不同版本的 jQuery,也可能会出现此问题。
回答by mark.inman
This usually has to do with a selector not being used properly. Check and make sure that you are using the jQuery selectors like intended. For example I had this problem when creating a click method:
这通常与未正确使用选择器有关。检查并确保您使用的是预期的 jQuery 选择器。例如,我在创建 click 方法时遇到了这个问题:
$("[editButton]").click(function () {
this.css("color", "red");
});
Because I was not using the correct selector method $(this) for jQuery it gave me the same error.
因为我没有为 jQuery 使用正确的选择器方法 $(this) 它给了我同样的错误。
So simply enough, check your selectors!
所以很简单,检查你的选择器!

