简体   繁体   English

脱机时出现错误Uncaught ReferenceError:未定义$(...)(匿名>函数)

[英]When offline getting error Uncaught ReferenceError: $ is not defined(…)(anonymous > function)

I have a following javascript (It toggles visibility of my menu) 我有以下javascript(可切换菜单的可见性)

   <!-- toggle visibility for filter -->
     <script type="text/javascript">
                  $(document).ready(function() {
                      $("#extra-content").hide();
                      $("#toggle-content").click(function(){
                          $("#extra-content").toggle();
                      });
                  });
     </script>

but when I am offline (I programme during my commute) I am getting error from this script 但是当我离线时(我在通勤期间编程),我从此脚本中获取错误

(index):101 Uncaught ReferenceError: $ is not defined(…)(anonymous function) @ (index):101 (索引):101未被捕获的ReferenceError:未定义$(...)(匿名函数)@(索引):101

How I can figure out what js file to copy locally to make it work offline? 如何确定要在本地复制的js文件以使其脱机工作?

UPDATE This is how I load jquery 更新这就是我加载jQuery的方式

<!-- Placed at the end of the document so the pages load faster -->
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="{{ STATIC_URL }}/static/jquery/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="{{ STATIC_URL }}/static/jquery/jquery-ui.js"></script>

You will also have an additional error in the console that indicates a 404 not found . 控制台中还将出现一个其他错误,指示404 not found

This is the file that you need to copy locally. 这是您需要在本地复制的文件。

Looking at the error this is almost certainly jQuery. 看着错误,这几乎可以肯定是jQuery。

How Jquery is loaded ? jQuery如何加载? If you get it by the cdn it's normal than you can't access it when offline. 如果您是通过CDN获得的,那是正常的情况,而离线时无法访问它。 Try to donwload it and install it locally 尝试下载并在本地安装

$ is not defined error is thrown when jquery file is not loaded. 未定义$时,未加载jquery文件时引发错误。 Since you are using jQuery "$(document).ready(function(){});" 由于您使用的是jQuery "$(document).ready(function(){});" , you must ensure that jquery is loaded, either you copy jquery.min.js file locally or you can use HTML Application Cache feature as you are working offline. ,您必须确保已加载jquery,可以在本地复制jquery.min.js文件,也可以在脱机工作时使用HTML Application Cache功能。 This will store your jquery.min.js file and will available untill you clear the cache. 这将存储您的jquery.min.js文件,并且在您清除缓存之前将一直可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM