Can't find variable: $

倾然丶 夕夏残阳落幕 提交于 2019-12-01 19:41:21

问题


var scriptFile = $(tempNode).attr("customJScriptSrc");

When passing this i get

“Reference Error: Can’t find variable: $”

Kindly suggest me any alternative methods.


回答1:


add this script:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

at top of the document(added before your javascript code).

or download the library and reference it in you code.




回答2:


I had this same problem and it was caused by me putting my .js file before the jQuery .js file in the DOM. This was causing an error because it was trying to read my .js file before recognizing that jQuery was even installed. Always put all your scripts in order of execution and alway at the very bottom of the body tag. This always makes sure that the page is fully loaded before trying to execute any javascript.

Before (Incorrect):

<script type="text/javascript" src="_javascript/rp-global.js"></script>
<script type="text/javascript" src="_javascript/jquery-3.2.1.min.js"></script>

After (Correct):

<script type="text/javascript" src="_javascript/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="_javascript/rp-global.js"></script>


来源:https://stackoverflow.com/questions/14889985/cant-find-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!