javascript 未捕获的类型错误:对象 [object Object] 没有方法“bxSlider”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19231730/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 14:49:54  来源:igfitidea点击:

Uncaught TypeError: Object [object Object] has no method 'bxSlider'

javascriptjqueryjquery-plugins

提问by Travis

I am getting this error in the console.

我在控制台中收到此错误。

Uncaught TypeError: Object [object Object] has no method 'bxSlider'

未捕获的类型错误:对象 [object Object] 没有方法“bxSlider”

I have no idea why this is happening though. I had all of this working perfectly but then when i put it into a NetSuite store it stops working.

我不知道为什么会发生这种情况。我让所有这些工作完美,但是当我将它放入 NetSuite 商店时,它停止工作。

This is running jQuery in NoConflict i don't need to change all of the "$" to jQuery in the plugin do I?

这是在 NoConflict 中运行 jQuery,我不需要将插件中的所有“$”更改为 jQuery,对吗?

This is where i am calling jQuery, the Plugin and the script for it.

这是我调用 jQuery、插件和它的脚本的地方。

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">jQuery.noConflict();</script>
<script type="text/javascript" src="/site/js/modernizr.custom.93936.js"></script>
<script src="/site/js/jquery.bxslider.js"></script>
<script>
jQuery(document).ready(function(){
  jQuery('.bxslider').bxSlider({
  auto: true,
  controls: false   
});

});
</script>

And this is the entire console error.

这是整个控制台错误。

Uncaught TypeError: Object [object Object] has no method 'bxSlider' dtv:57 (anonymous function) dtv:57 n jquery.min.js:2 o.fireWith jquery.min.js:2 e.extend.ready jquery.min.js:2 c.addEventListener.B

Uncaught TypeError: Object [object Object] has no method 'bxSlider' dtv:57 (anonymous function) dtv:57 n jquery.min.js:2 o.fireWith jquery.min.js:2 e.extend.ready jquery.min .js:2 c.addEventListener.B

What could be the cause here i am so lost have been trying every little thing that i know and nothing is making it work.

我很迷茫的原因是什么,我一直在尝试我所知道的每一件小事,但没有任何事情可以让它发挥作用。

采纳答案by Sumit Raghav

May be it because of jquery conflict. Please recheck your code, may be you added jquery twice. Or change the latest jquery.

可能是因为 jquery 冲突。请重新检查您的代码,可能是您添加了两次 jquery。或者更换最新的jquery。

回答by Marty

It may be because of a jquery conflict and it is good advice to check your code (for instace using the console or developer tools of your favorite browser) for jquery being loaded twice.

这可能是因为 jquery 冲突,最好检查您的代码(例如使用控制台或您喜欢的浏览器的开发人员工具)是否加载了两次 jquery。

You should also check to see if the js file for bxSlider is being loaded in the console as there may be a typo in the path to it.

您还应该检查 bxSlider 的 js 文件是否正在控制台中加载,因为它的路径中可能存在拼写错误。

One other reason that could cause this is the order in which scripts are loaded. If bxSlider is loaded before jquery it will give this error. You can check this by looking at the source code for the page or by looking at Network tab in developer tools.

另一个可能导致这种情况的原因是脚本的加载顺序。如果在 jquery 之前加载 bxSlider,则会出现此错误。您可以通过查看页面的源代码或查看开发人员工具中的网络选项卡来检查这一点。

回答by Mark

I found that putting

我发现把

jQuery(document).ready(function(){
  jQuery('.bxslider').bxSlider({
  auto: true,
  controls: false   
});

})

in a file (settings.js, was also more efficient in detecting where the error was and apparently more likeable by WordPress.

在文件 ( settings.js, 在检测错误位置方面也更有效,而且显然更受 WordPress 喜爱。

回答by DDDD

This is also a problem if you have not raked assets.

如果您还没有收集到资产,这也是一个问题。

rake assets:clean && rake assets:precompile

回答by Amanda

I got this when omitting the braces () when declaring the function.

我在声明函数时省略大括号 () 时得到了这个。

Incorrect code:

不正确的代码:

var calcResults = (function () {
.....
});

Correct code:

正确代码:

var calcResults = (function () {
.....
})();   //<<--  these () were missing