[英]jQuery uncaught TypeError: Infinite scroll
所以,我按照教程實現無限滾動: 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>
您是否在頁眉中添加了插件文件?
您必須從您提供的插件頁面下載它並將其添加為:
<script src="jquery.infinitescroll.js"></script>
在腳本標記之后的頁面的head部分,你加載jQuery請調整src到你放置js的目錄的路徑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.