简体   繁体   English

$.fn 不是对象

[英]$.fn is not an object

I'm trying out using scrollspy with bootstrap, and I'm running into some errors with it.我正在尝试将 scrollspy 与 bootstrap 结合使用,但遇到了一些错误。 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错误控制台不断返回: TypeError: 'undefined' is not an object (evaluating '$.fn') ,在 bootstrap-scrollspy.js 的第 124 行,这是这一行

var old = $.fn.scrollspy

, which is under the ScrollSpy Plugin Definition. ,这是在 ScrollSpy 插件定义下。 I am using the code directly taken from this jsFiddle我正在使用直接取自这个 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.在页面上包含 Bootstrap 之前,请确保包含 jQuery。
  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.在您的脚本行中,我假设您已经从 jQuery 包含中删除了“slim”。 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).如果不是,则完整性检查失败,并且 jQuery 未加载..(我刚刚遇到了同样的问题)。

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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