ReferenceError:找不到变量:$ [英] ReferenceError: Can't find variable: $

查看:33
本文介绍了ReferenceError:找不到变量:$的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个很正常的问题,但我无法解决.
我试图修复jQuery脚本数十次,但这只是行不通.几周后,它突然停止工作.

我很确定我包含了jQuery脚本,并且确实测试了该网站是否还活着.
但是,

我在这里迷路了,该如何解决?它运行得很好,然后突然繁荣起来,一无所有,它停止了工作.一直在尝试解决此问题,但我无法解决.

干杯,谢谢阅读

根据评论的要求,包括了 JSFiddle .希望我包括必要的代码.

解决方案

将所有"$"替换为"jQuery".如果可行: jQuery.noConflict()

I've come across a fairly normal problem, but I can't solve it.
I tried to fix the jQuery scripts dozens of times, but it just won't work. It suddenly just stopped working after a few weeks.

I am positive that I included the jQuery script, and I did test if the site was alive.
However, it seems like my browser or server ain't loading it with the site load...

It load my Google Analytics script perfectly fine, but it won't load the jQuery script. Even if I host i myself.

This is the code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="scripts/ganalytics.js" type="text/javascript"></script>

<script type="text/javascript">
  $(document).ready(function(){
    $('img').hover(function(){
      $(this).data('jpg', $(this).attr('src'));
      $(this).attr('src',$(this).data('gif'));
    },
    function(){
      $(this).attr('src',$(this).data('jpg'));
    });
  });
</script>

Here, it produces the error on line #5 or line #15 in my website

I am lost here, how do I fix this? It was working great, and then suddenly, boom, out of nothing, it stopped working. Have been trying to fix this, but I can't figure it out.

Cheers, thanks for reading

EDIT: Included a JSFiddle as it was requested in the comments. Hope I included the necessary code.

解决方案

Replace all "$" with "jQuery". If that works: jQuery.noConflict()

这篇关于ReferenceError:找不到变量:$的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆