Can't find variable: $

后端 未结 2 1553
无人及你
无人及你 2021-01-20 00:51
var scriptFile = $(tempNode).attr(\"customJScriptSrc\");

When passing this i get

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

相关标签:
2条回答
  • 2021-01-20 01:11

    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>
    
    0 讨论(0)
  • 2021-01-20 01:19

    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.

    0 讨论(0)
提交回复
热议问题