所以,我按照教程来实现无限滚动:http://www.infinite-scroll.com/infinite-scroll-jquery-plugin/comment-page-3/
在我的页脚中,我添加了 <script type="text/javascript" src="http://example.com/js/jquery.infinitescroll.min.js"></script>
在 javascript.js 文件中,我添加了以下内容(与教程相同):
// infinitescroll() is called on the element that surrounds
// the items you will be loading more of
$('#content').infinitescroll({
navSelector : "div.navigation",
// selector for the paged navigation (it will be hidden)
nextSelector : "div.navigation a:first",
// selector for the NEXT link (to page 2)
itemSelector : "#content div.post"
// selector for all items you'll retrieve
});
但是,我得到 Uncaught TypeError: jQuery(...).infinitescroll is not a function
错误。
因此,我添加了 js 文件并添加了与教程几乎相同的脚本。我可以看到页面上显示了 js 文件和脚本,但仍然出现错误。
有人能帮我解释为什么我会收到错误吗?
谢谢!
最佳答案
您应该确保您的初始化代码在 $(function(){}) 中,因为您需要在运行 infinitescroll 之前准备好 DOM。然后你必须确保你的页面中有一个 id="content"的元素。所以,确保你有这样的东西:
<div id="content">...</div>
<script src="jquery.infinitescroll.js"></script>
<script>
$(function() {
// infinitescroll() is called on the element that surrounds
// the items you will be loading more of
$('#content').infinitescroll({
navSelector : "div.navigation",
// selector for the paged navigation (it will be hidden)
nextSelector : "div.navigation a:first",
// selector for the NEXT link (to page 2)
itemSelector : "#content div.post"
// selector for all items you'll retrieve
});
});
</script>
关于javascript - jQuery 未捕获类型错误 : Infinite scroll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32244445/