Javascript Shopify,TypeError:$(…)。jcarousel不是函数
因此,我看到了这个标题的其他问题,我不认为我遇到了与他们相同的问题(特别是因为我没有使用Drupal,而且文件似乎正在加载到页面标题中,如下所示)。我知道它找不到那个函数,但我不知道为什么。这是theme.liquid head中的代码,用于设置javascript和样式:Javascript Shopify,TypeError:$(…)。jcarousel不是函数,javascript,jquery,css,shopify,jcarousel,Javascript,Jquery,Css,Shopify,Jcarousel,因此,我看到了这个标题的其他问题,我不认为我遇到了与他们相同的问题(特别是因为我没有使用Drupal,而且文件似乎正在加载到页面标题中,如下所示)。我知道它找不到那个函数,但我不知道为什么。这是theme.liquid head中的代码,用于设置javascript和样式: <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"&g
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="canonical" href="{{ canonical_url }}" />
{% assign maxmeta = 155 %}
{% if template contains 'product' %}
<meta name="description" content="{{ product.description | strip_html | strip_newlines | truncate: maxmeta | escape }}" />
{% elsif template contains 'page' %}
<meta name="description" content="{{ page.content | strip_html | strip_newlines | truncate: maxmeta | escape }}" />
{% elsif template == 'index' and shop.description != '' %}
<meta name="description" content="{{ shop.description }}" />
{% endif %}
{{ 'skinCustom.css' | asset_url | stylesheet_tag }}
{{ 'jquery-1.4.2.min.js' | asset_url | script_tag }}
{{ 'jquery.jcarousel.min.js' | asset_url | script_tag }}
{% if template == 'index' %}
<title>{{ shop.name }}</title>
{% elsif template == '404' %}
<title>Page Not Found | {{ shop.name }}</title>
{% else %}
<title>{{ page_title }} | {{ shop.name }}</title>
{% endif %}
{% include 'fb-open-graph' %}
{% case settings.header_font %}
{% when "Rancho, cursive" %}
<link href='http://fonts.googleapis.com/css?family=Rancho' rel='stylesheet' type='text/css'>
{% when "'Amatic SC', cursive" %}
<link href='http://fonts.googleapis.com/css?family=Amatic+SC:700' rel='stylesheet' type='text/css'>
{% when "'Sancreek', cursive" %}
<link href='http://fonts.googleapis.com/css?family=Sancreek' rel='stylesheet' type='text/css'>
{% when "'Ubuntu Condensed', sans-serif" %}
<link href='http://fonts.googleapis.com/css?family=Ubuntu+Condensed' rel='stylesheet' type='text/css'>
{% endcase %}
{{ 'style.css' | asset_url | stylesheet_tag }}{% if template contains 'product' and settings.main_image_display == 'Lightbox' %}
{{ 'jquery.fancybox-1.3.4.css' | asset_url | stylesheet_tag }}{% endif %}
{{ 'modernizr.js' | asset_url | script_tag }}
{{ 'option_selection.js' | shopify_asset_url | script_tag }}
{% if template contains 'customers' %}
{{ "shopify_common.js" | shopify_asset_url | script_tag }}
{{ "customer_area.js" | shopify_asset_url | script_tag }}
{% endif %}
<script type="text/javascript">
$(document).ready(function() {
$('#mycarousel').jcarousel({ vertical: true, scroll: 1, start: 3 });
});
</script>
{{ '//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js' | script_tag }}
{{ content_for_header }}
{%assign maxmeta=155%}
{%如果模板包含“产品”}
{%els如果模板包含“页面”}
{%elsif模板=='index'和shop.description!=''%}
{%endif%}
{{'skinCustom.css'|资产| url |样式表标签}
{{'jquery-1.4.2.min.js'|资产| url |脚本(标记)}
{{'jquery.jcarousel.min.js'|资产| url |脚本(标记)}
{%if模板=='索引'%}
{{shop.name}
{%elsif模板=='404%}
找不到页面|{{shop.name}
{%else%}
{{page_title}}{{shop.name}}
{%endif%}
{%include'fb open graph%}
{%case settings.header\u font%}
{%when“Rancho,草书”%}
{%当“'Amatic SC',草书”%}
{%当“'Sancreek',草书”%}
{%当“'Ubuntu Condensed',sans serif”%}
{%endcase%}
{{'style.css'| asset|url | stylesheet_tag}}{%如果模板包含'product'和设置。main_image_display=='Lightbox'}
{{'jquery.fancybox-1.3.4.css'|资产| url |样式表(标记)}{%endif%}
{{'modernizer.js'|资产| url |脚本(标记)}
{{'option_selection.js'| shopify_asset_url | script_tag}
{%如果模板包含“客户”%}
{{“shopify_common.js”| shopify_asset_url | script_tag}
{{“customer_area.js”| shopify_asset_url | script_tag}
{%endif%}
$(文档).ready(函数(){
$(#mycarousel').jcarousel({vertical:true,scroll:1,start:3});
});
{{'//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js'| script_tag}}
{{content_for_header}}
当页面呈现时,我得到以下信息(我编辑掉了与此问题无关的额外内容)。我将箭头指向jcarousel所依赖的js和样式页面的引用。在我尝试将其转移到Shopify项目之前,我在一个单独的文件中有一个这样的例子
<head>
<meta charset="UTF-8">
--> <link href="http://cdn.shopify.com/s/files/1/0212/5406/t/1/assets/skinCustom.css?241" rel="stylesheet" type="text/css" media="all" />
--> <script src="http://cdn.shopify.com/s/files/1/0212/5406/t/1/assets/jquery-1.4.2.min.js?241" type="text/javascript"></script>
--> <script src="http://cdn.shopify.com/s/files/1/0212/5406/t/1/assets/jquery.jcarousel.min.js?241" type="text/javascript"></script>
<link href="http://cdn.shopify.com/s/files/1/0212/5406/t/1/assets/style.css?241" rel="stylesheet" type="text/css" media="all" />
<script src="http://cdn.shopify.com/s/files/1/0212/5406/t/1/assets/modernizr.js?241" type="text/javascript"></script>
<script src="http://cdn.shopify.com/s/shopify/option_selection.js?aaf2a68ed9671e345bbc7eef1e63563c51bde6eb" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
ERROR HERE --> $('#mycarousel').jcarousel({ vertical: true, scroll: 1, start: 3 });
});
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="/global/theme-controls.css" type="text/css" />
</head>
-->
-->
-->
$(文档).ready(函数(){
此处出错-->$('#mycarousel').jcarousel({vertical:true,scroll:1,start:3});
});
我能想象到的唯一可能发生的事情是其他脚本文件之一把事情搞砸了。但除了删除其他脚本文件外,我不确定如何调试它。如果有人遇到过类似的问题或对此有一些见解,我将不胜感激。除了不正确的实现(比如把脚本忘在脑后),其他问题似乎都找不到答案。我可能在做一些愚蠢的事情,但我已经研究和查看了很多次,我看不出它是什么
谢谢
Alan正如@gaoshan88评论的那样,我加载了两次jquery。因为当我最初只添加jcarousel.js脚本时,它说没有jquery文件。所以我自己又添加了一次,不知道shopify也通过google.api添加了最新版本。我不太清楚为什么jquery一开始就给了我这个错误,但是当我把google.api脚本referee拿出来的时候,它成功了。感谢您的快速回复,我对此表示感谢。正如@gooshan88评论的那样,我加载了两次jquery。因为当我最初只添加jcarousel.js脚本时,它说没有jquery文件。所以我自己又添加了一次,不知道shopify也通过google.api添加了最新版本。我不太清楚为什么jquery一开始就给了我这个错误,但是当我把google.api脚本referee拿出来的时候,它成功了。感谢您的快速回复,我对此表示感谢。我将把上面的评论放到回复表中
这有两个问题。首先,您将加载jQuery两次。不要那样做。其次,jQuery对
$
的使用可能会与其他javascript库发生冲突,因此您应该使用jQuery
或使用jQuery的我将上面的评论放入响应表单中
这有两个问题。首先,您将加载jQuery两次。不要那样做。其次,jQuery对
$
的使用可能与其他javascript库冲突,因此您应该使用jQuery
或使用jQuery的为什么要加载jQuery两次?一个可能的问题是jQuery使用的美元符号。尝试用jQuery
替换它,这样您就有了jQuery(“#mycarousel”)
或者尝试使用jQuery的无冲突模式。我看了那么多次。。。我想我还需要一双眼睛。问题在于,两次加载jquery会把事情搞砸。我这样做是因为当我最初尝试使用jcarousel时,它说它找不到它所依赖的jquery。所以我自己添加了它,只是假设它还没有加载。谢谢你的回复。我已经花了好几个小时试图弄明白这一点。如果你所有的订单都正确,并且没有冲突,会发生什么。它仍然无法被识别(但你可以在控制台中看到它被加载。为什么要加载两次jquery?一个可能的问题是jquery使用的美元符号。尝试将其替换为jquery
,这样就有了jquery(“#mycarousel”)
或者尝试使用jquery的noconflict模式。我看了这么多次……我想我需要第二双眼睛。问题是,两次加载jquery会把事情搞砸。我这么做是因为当我最初尝试使用jcarousel时,它说找不到它所依赖的jquery。所以我自己添加了它,只是假设它不是已经加载了。谢谢你的回复。我已经花了几个小时试图解决这个问题。如果你所有的订单都正确,并且