jQuery(“#mycarousel”).jcarousel 不是函数

发布于 2024-12-29 10:18:16 字数 892 浏览 3 评论 0原文

我一定在这里做了一些非常愚蠢的事情,但我已经绞尽脑汁了一段时间了,但我无法找到问题所在。

在此页面上: http://ww2.accudata.com/

我正在尝试实现 jCarousel,但不断收到此错误:

jQuery("#mycarousel").jcarousel 不是函数

这是我的标题中的内容:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js?ver=1.6.4"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.jcarousel.min.js"></script>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/js/skins/carousel/skin.css" />

<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#mycarousel').jcarousel({

});
});
</script>

据我所知,我正在以正确的顺序加载所有脚本,并且我已经验证它们都是那里。那么为什么说它不是一个函数呢?

I must be doing something really stupid here, but I've been beating my head against it for a while and I haven't been able to find what's wrong.

On this page:
http://ww2.accudata.com/

I'm trying to implement jCarousel, and I keep getting this error:

jQuery("#mycarousel").jcarousel is not a function

Here's what I have in my header:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js?ver=1.6.4"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.jcarousel.min.js"></script>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/js/skins/carousel/skin.css" />

<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#mycarousel').jcarousel({

});
});
</script>

So as far as I can tell, I'm loading all of the scripts in the correct order, and I have verified that they are all there. So why does it say it's not a function?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

世界和平 2025-01-05 10:18:16

在第 39 行,您将重新加载 jQuery,这会覆盖 jQuery 对象,从而删除 .jcarousel 函数。确保您仅加载 jQuery 一次。

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js?ver=1.6.4"></script>
<script type="text/javascript" src="http://ww2.accudata.com/wp-content/themes/accudata/js/jquery.jcarousel.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://ww2.accudata.com/wp-content/themes/accudata/js/skins/carousel/skin.css" />

<script type="text/javascript">
jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({ //Would work if you called it here, but it gets deferred until the DOM is loaded

    });
});
</script>

...

<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js?ver=1.6.4'></script>
<!-- This gets loaded after you load the plugin, overwriting the jQuery object -->

On line 39, you are reloading jQuery, which overwrites the jQuery object, removing the .jcarousel function. Make sure you are loading jQuery only once.

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js?ver=1.6.4"></script>
<script type="text/javascript" src="http://ww2.accudata.com/wp-content/themes/accudata/js/jquery.jcarousel.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://ww2.accudata.com/wp-content/themes/accudata/js/skins/carousel/skin.css" />

<script type="text/javascript">
jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({ //Would work if you called it here, but it gets deferred until the DOM is loaded

    });
});
</script>

...

<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js?ver=1.6.4'></script>
<!-- This gets loaded after you load the plugin, overwriting the jQuery object -->
断念 2025-01-05 10:18:16

您看到的错误基本上意味着:

"we tried looking for the jcarousel function, and couldn't find it."

打开页面源代码并查看正在呈现的 HTML。 .js 文件的路径是否正确且符合您的预期?大多数时候,这是导致此类问题的原因。

因此,一旦您确定对 .js 文件的引用正确,请尝试如下操作:

<script type="text/javascript">
    $(document).ready(function() {
        $('#mycarousel').jcarousel({
            //Settings here.
        }); 
    });
</script>

The error you're seeing basically means:

"we tried looking for the jcarousel function, and couldn't find it."

Open the page source and see what HTML is being rendered. Are you paths to the .js files correct and what you expect? Most of the times this is the cause of these types of problems.

So once you're sure that your references to the .js files are correct, try something like this:

<script type="text/javascript">
    $(document).ready(function() {
        $('#mycarousel').jcarousel({
            //Settings here.
        }); 
    });
</script>
风吹短裙飘 2025-01-05 10:18:16

您收到 jcarousel 函数未知的错误,这意味着带有 jcarousel 函数的 js 文件未正确加载。 (对 JQuery 本身的引用有效,因为 jQuery(document).ready... 没有给您错误)

查看渲染的 HTML 并查看路径是否使文件与他的实际位置相匹配。 (他们不是...)

顺便说一句,你为什么不使用 JQuery 别名 $
jQuery('#mycarousel') =>; $('#mycarousel')

JQuery 口号是“少写多做

You get an error that jcarousel function is unknown which means that the js file with the jcarousel function was not loaded correctly. (The reference to JQuery itself works because the jQuery(document).ready... didn't give you an error)

Look at the rendered HTML and see if the path to the file match to his actual location. (They are not...)

By the way, why aren't you using JQuery alias $?
jQuery('#mycarousel') => $('#mycarousel')

JQuery slogan is "Write less do more"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文