jQuery: How can I use “$” instead of “jQuery”?

前端 未结 3 1307
天命终不由人
天命终不由人 2021-02-11 01:43

I have simple jQuery in my site, yet I keep getting this error:

Uncaught TypeError: Property \'$\' of object [object DOMWindow] is not a function
相关标签:
3条回答
  • 2021-02-11 01:50

    First, jQuery objects are a lot like arrays, so [object DOMWindow] actually is a jQuery object most likely.

    You might have a syntax error, like a missing semicolon, right before the call to $(document) which is making the $ look like a property access.

    0 讨论(0)
  • 2021-02-11 02:11

    You can wrap your code:

    (function($) {
        // here $ would be point to jQuery object
        $(document).ready(function() {
            $('#pass').keyup( ... );
        });
    })(jQuery);
    
    0 讨论(0)
  • 2021-02-11 02:14

    You probably have jQuery noConflict mode enabled somewhere in your code, see: http://api.jquery.com/jQuery.noConflict/

    jQuery.noConflict(); // Stops $ from workng
    
    0 讨论(0)
提交回复
热议问题