首页 > 技术文章 > (前端) Uncaught TypeError: $(…).scrollSpy is not a function解决

mryaohu 2020-07-07 22:22 原文

$('body').scrollspy({
target: '#nav',
offset: $(window).height() / 2
});
报错:

Uncaught TypeError: $(…).scrollSpy is not a function

 

首先检查自己引入jquery是不是在其他js语句之前。

其次想要使用scrollspy().必须提前 import bootstrap.min.js .

<script type="text/javascript" src="static/js/bootstrap.min.js"></script>

官网:https://getbootstrap.com/docs/4.0/components/scrollspy/

 

推荐阅读