Javascript 未捕获的类型错误:对象 #<Object> 没有方法“movingBoxes”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5355805/
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
Uncaught TypeError: Object #<Object> has no method 'movingBoxes'
提问by Collin O'Connor
Im trying to use the movingBoxes plugin with my asp.net mvc site and it is not working (obviously). I have the movingboxes.js imported in my head tag in the site.master like so
我试图在我的 asp.net mvc 站点中使用移动框插件,但它不起作用(显然)。我在 site.master 的 head 标签中导入了movingboxes.js,就像这样
<script src="<%: Url.Content("~/Scripts/jquery.movingboxes.js")%>" type="text/javascript"></script>
and the browser successfully gets this script. Now i have a regular view that inherits from the site.master that has this little bit of jquery in it that calls the movingBoxes plugin
并且浏览器成功获取了这个脚本。现在我有一个从 site.master 继承的常规视图,其中有一点点 jquery 调用movingBoxes 插件
<script type="text/javascript">
$(document).ready(function () {
$($('#slider-one'));
$('#slider-one').movingBoxes({
startPanel: 1,
panelWidth: .5,
fixedHeight: false
});
$('#slider-two').movingBoxes({
startPanel: 1,
panelWidth: .5,
fixedHeight: false
});
});
</script>
When i view the page. Every thing works fine (including other jquery stuff) except for this plugin and i get this error
当我查看页面时。除了这个插件,一切都很好(包括其他 jquery 的东西),我收到了这个错误
And here is the description of the error
这是错误的描述
Any help would be appreciated
任何帮助,将不胜感激
EDIT
编辑
So apparently I had this:
所以显然我有这个:
<script type="text/javascript" src="../../Scripts/jquery-1.4.1.js" />
<script src="<%: Url.Content("~/Scripts/jquery.movingboxes.js")%>" type="text/javascript"></script>
And it works now by changing it to this:
它现在可以通过将其更改为:
<script type="text/javascript" src="../../Scripts/jquery-1.4.1.js"></script>
<script src="<%: Url.Content("~/Scripts/jquery.movingboxes.js")%>" type="text/javascript"></script>
回答by Hacknightly
There are a few things you can try to get this working.
您可以尝试一些方法来使其正常工作。
Be ABSOLUTELY sure your script is being pulled into the page, one way to check is by using the 'sources' tab in the Chrome Debugger and searching for the file.
Be sure that you've included the script after you've included jQuery, as it is most certainly dependant upon that.
绝对确保您的脚本已被拉入页面,一种检查方法是使用 Chrome 调试器中的“源”选项卡并搜索文件。
确保在包含 jQuery 之后包含了脚本,因为它肯定依赖于它。
Other than that, I checked out the API and you're definitely doing everything right as far as I can see. Best of luck friend!
除此之外,我检查了 API,就我所见,您肯定做对了一切。祝朋友好运!
EDIT: Ensure you close your script tag. There's an answer below that points to that being the solution.
编辑:确保关闭脚本标记。下面有一个答案指出这是解决方案。
回答by SaschaM78
Please keep in mind that only a few elements can be self-closing, most others have to be closed through adding an explicit end tag. In the above case, the first script tag was not closed properly, the end script tag of the second script then closed the script section, causing only the first script to be loaded as external script source and ignoring the second script.
请记住,只有少数元素可以自动关闭,大多数其他元素必须通过添加明确的结束标记来关闭。在上面的例子中,第一个脚本标签没有正确关闭,第二个脚本的结束脚本标签然后关闭了脚本部分,导致只有第一个脚本作为外部脚本源加载而忽略了第二个脚本。
More info about which tags can be self-closed, have a look at the W3C drafts for HTML5 (although the definition was no different in earlier HTML-versions):
有关哪些标签可以自闭合的更多信息,请查看 HTML5 的 W3C 草案(尽管早期 HTML 版本中的定义没有不同):
http://www.w3.org/TR/html5/syntax.html#end-tags(8.1.2.1, Point 6)
http://www.w3.org/TR/html5/syntax.html#end-tags(8.1.2.1,第 6 点)
回答by Gazu
I had the same problem. I changed the order of the scripts in the headpart, and it worked for me. Every script the plugin needs - needs to stay close.
我有同样的问题。我改变了头部脚本的顺序,它对我有用。插件需要的每个脚本 - 需要保持密切。
For example:
例如:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#slider').cycle({
fx: 'fade'
});
});
</script>
回答by racl101
I just had this same problem with the jquery Responsive Slides plugin (http://responsive-slides.viljamis.com/).
我刚刚在 jquery 响应式幻灯片插件 ( http://responsive-slides.viljamis.com/) 上遇到了同样的问题。
I fixed it by not using the jQuery short version $(".rslides").responsiveSlides(..
but rather the long version: jQuery(".rslides").responsiveSlides(...
我通过不使用 jQuery 短版$(".rslides").responsiveSlides(..
而是使用长版来修复它:jQuery(".rslides").responsiveSlides(...
So switching $
to jQuery
so as not to cause conflict or using the proper jQuery no conflict mode (http://api.jquery.com/jQuery.noConflict/)
因此切换$
到jQuery
以免引起冲突或使用正确的 jQuery 无冲突模式(http://api.jquery.com/jQuery.noConflict/)
回答by Valamas
When I had this problem it was because I was trying to use an actual function in place of an anonymous function.
当我遇到这个问题时,是因为我试图使用实际函数代替匿名函数。
Incorrect:
不正确:
$(document).on('change', "#MyId", MyFunction());
Correct
正确的
$(document).on('change', "#MyId", MyFunction);
or also correct and if you need to pass event object or other params.
或者也正确,如果您需要传递事件对象或其他参数。
$(document).on('change', "#MyId", function(e) { MyFunction(e); });
回答by Victor Augusto
Actually i think that you have downloaded just a part of the script. Try to check 'Core' checkbox before download the whole script in jquery site.
实际上,我认为您只下载了脚本的一部分。在 jquery 站点下载整个脚本之前,尝试检查“核心”复选框。
回答by Serhii Matrunchyk
I had a such problem too because i was using IMG tag and UL tag.
我也有这样的问题,因为我使用的是 IMG 标签和 UL 标签。
Try to apply the 'corners' plugin to elements such as $('#mydiv').corner()
, $('#myspan').corner()
, $('#myp').corner()
but NOT for $('#img').corner()
!
This rule is related with adding child DIVs into specified element for emulation round-corner effect. As we know IMG element couldn't have any child elements.
尝试将 'corners' 插件应用于诸如$('#mydiv').corner()
, 之类的元素$('#myspan').corner()
,$('#myp').corner()
但不适用于$('#img').corner()
! 此规则与将子 DIV 添加到指定元素以模拟圆角效果有关。我们知道 IMG 元素不能有任何子元素。
I've solved this by wrapping a needed element within the div and changing IMG to DIV with background: CSS property.
我通过在 div 中包装一个需要的元素并将 IMG 更改为具有 background: CSS 属性的 DIV 解决了这个问题。
Good luck!
祝你好运!
回答by Aakash Agrawal
i had the same problem i had linked jquery twice . The later version was overwriting my plugin.
我有同样的问题,我曾两次链接 jquery。后来的版本覆盖了我的插件。
I just removed the later jquery it started working.
我刚刚删除了它开始工作的后来的 jquery。
回答by Rob Erskine
It's also a good idea to make sure you're using the correct version of jQuery. I had recently acquired a project using jQuery 1.6.2 that wasn't working with the hoverIntent plugin. Upgrading it to the most recent version fixed that for me.
确保您使用正确版本的 jQuery 也是一个好主意。我最近获得了一个使用 jQuery 1.6.2 的项目,该项目无法与 hoverIntent 插件一起使用。将其升级到最新版本为我解决了这个问题。
回答by vikingben
I found that I was using a selector for my rendorTo div that I was using to render my column highcharts graph. Apparently it adds the selector for you so you just need to pass id.
我发现我正在为我的 rendorTo div 使用一个选择器,我用它来呈现我的列 highcharts 图。显然它为您添加了选择器,因此您只需要传递 id。
renderTo: $('#myGraphDiv') to a string 'myGraphDiv' this fixed the error hope this helps someone else out as well.
renderTo: $('#myGraphDiv') 到字符串 'myGraphDiv' 这修复了错误,希望这也能帮助其他人。