简体   繁体   English

未定义$。 未捕获的参考错误

[英]`$` is not defined. Uncaught reference error

I'm new to JavaScript and JQuery. 我是JavaScript和JQuery的新手。 I am facing this problem where the browser is detecting that $ is not defined. 我在浏览器检测到未定义$时遇到此问题。 I have seen a lot of solutions to this problem. 我已经看到了很多解决此问题的方法。 But turns out none of them are working for me. 但是事实证明他们都没有为我工作。 In my HTML, I'm loading the jquery library from my local directory, before calling my script. 在我的HTML中,在调用脚本之前,我要从本地目录加载jquery库。

Directory that contains the jquery library and the script 包含jquery库和脚本的目录

HTML header where I'm loading the scripts 我在其中加载脚本的HTML标头

DOM error that the browser shows me every time I load the page 每次加载页面时浏览器显示的DOM错误

Somehow, I'm not able to find a solution to this error. 不知何故,我找不到此错误的解决方案。 Your help is very much appreciated. 非常感激你的帮助。 Thank you for your time and efforts. 感谢您的时间和精力。

You need to remove async from your script tags, as this is essentially loading and running those files in parallel, meaning your script.js file could be running before your jquery files are even loaded. 您需要从脚本标签中删除async ,因为这实际上是并行加载和运行这些文件,这意味着script.js文件可能在加载jquery文件之前script.js运行。

Also, you don't need to load both the minified and unminified versions of jQuery. 另外,您无需同时加载jQuery的最小版本和未最小版本。 Just load the minified version. 只需加载缩小版本。

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

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