javascript - Shopify,TypeError : $(. ..).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">
  <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 }}

当页面呈现时,我得到以下信息(我删除了与此问题无关的额外内容)。我把箭头指向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>

我能想到的唯一可能发生的事情是其他脚本文件之一搞砸了。但是我不太确定除了取出其他脚本文件之外我将如何调试它。如果有人遇到类似问题或对此有一些见解,我将不胜感激。除了不正确的实现之外,其他问题似乎都没有得到答案(比如将该脚本留在头脑之外)。我可能在做一些愚蠢的事情,但我已经研究并查看了无数次,但我看不出它是什么。

谢谢,

艾伦

最佳答案

我正在将上面的评论放入回复表中。

这有两个问题。首先,您要加载 jQuery 两次。不要那样做。其次,jQuery 对 $ 的使用可能会与其他 javascript 库冲突,因此您应该使用 jQuery 或使用 jQuery 的 noconflict mode.

关于javascript - Shopify,TypeError : $(. ..).jcarousel 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14845115/

相关文章:

javascript - 在 iframe 中渲染电子邮件时如何处理 cid 图像源

javascript - 使用 jQuery 单击不受控制的多个表单提交

用于响应式设计的 HTML 大小单位

javascript - 完整的下拉菜单 OnClick

css - 如何在 css3 多背景中为重复背景提供左右填充/边距?

javascript - 带有动态标题和单元格的 Angular 7 Material 表

javascript - 将字符串名称转换为javascript变量名称?

javascript - 单击显示确认框

jquery json 对象

jquery 颜色,RGB 到 HSL 并返回