简体   繁体   中英

$.fn is not an object

I'm trying out using scrollspy with bootstrap, and I'm running into some errors with it. The error console keeps returning this: TypeError: 'undefined' is not an object (evaluating '$.fn') , on line 124 of bootstrap-scrollspy.js, which is this line

var old = $.fn.scrollspy

, which is under the ScrollSpy Plugin Definition. I am using the code directly taken from this jsFiddle

Does anyone know why this is happening?

I would double check two things:

  1. Make sure you're including jQuery before you're including Bootstrap on the page.
  2. Make sure no other libraries (eg, prototype) are overriding the $ variable.

On your script line I assume you have removed "slim" from jQuery include. But did you remove the "integrity" checksum? if not, the integrity check is failing, and jQuery isn't loading.. (I just had this same issue).

for example this:

<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

should be

<script src="https://code.jquery.com/jquery-3.3.1.min.js" crossorigin="anonymous"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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