JavaScript/jQuery - “$ is not defined- $function()” error

后端 未结 8 1979
轻奢々
轻奢々 2020-11-30 08:15

I am trying to run a JavaScript/jQuery function and Firebug gets the error:

$ is not defined $(function()\".

The JavaScript code is placed

相关标签:
8条回答
  • 2020-11-30 08:49

    if you are trying to use jquery in your electron app before adding jquery you should add it to your modules:

    <script>
        if (typeof module === 'object') {
            window.module = module;
            module = undefined;
        }
    </script>
    <script src="js/jquery-3.5.1.min.js"></script>
    
    0 讨论(0)
  • 2020-11-30 08:52

    You need to include the jQuery library on your page.

    You can download jQuery here and host it yourself or you can link from an external source like from Google or Microsoft.

    Google's:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    

    Microsoft's:

    <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.6.2.min.js">
    

    0 讨论(0)
  • 2020-11-30 08:52

    Include jquery.js and if it is included, load it before any other JavaScript code.

    0 讨论(0)
  • 2020-11-30 08:55

    Try:

    (function($) {
        $(function() {
            $('.update').live('change', function() {
                formObject.run($(this));
            });
        });
    })(jQuery);
    

    By using this way you ensure the global variable jQuery will be bound to the "$" inside the closure. Just make sure jQuery is properly loaded into the page by inserting:

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    

    Replace "http://code.jquery.com/jquery-1.7.1.min.js" to the path where your jQuery source is located within the page context.

    0 讨论(0)
  • 2020-11-30 09:02

    You must not have made jQuery available to your script.

    Add this to the top of your file:

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    

    This issue is related to the jQuery/JavaScript file not added to the PHP/JSP/ASP file properly. This goes out and gets the jQuery code from the source. You could download that and reference it locally on the server which would be faster.

    Or either one can directly link it to jQuery or GoogleCDN or MicrosoftCDN.

    How do add jQuery to your webpage

    0 讨论(0)
  • 2020-11-30 09:04

    This may be useful to someone:

    If you already got jQuery but still get this error, check you include jQuery before the js that uses it, specially if you use @RenderBody() in ASP.NET C#

    You have to include jQuery before the @RenderBody() if you include the js inside the view that @RenderBody() calls.

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