您有一个Main Jsp文件,其中包含了jquery.infinite-scroll.js。这个main.jsp有一个包含jsp,例如incl.jsp。现在无限滚动的功能在主jsp中定义,如
$(document).ready(function () {
$(function(){
var $container = $('#container');
$container.imagesLoaded( function(){
$container.isotope({
itemSelector: '.box',
gutterWidth: 10
});
});
$container.infinitescroll({
navSelector : '#page-nav', // selector for the paged navigation
nextSelector : '#page-nav a', // selector for the NEXT link (to page 2)
itemSelector : '.box', // selector for all items you'll retrieve
debug: true,
loading_image: 'http://i.imgur.com/6RMhx.gif',
loading: {
finishedMsg: 'No more pages to load.',
img: 'http://i.imgur.com/6RMhx.gif'
}
},
// trigger Masonry as a callback
function( newElements ) {
console.log('I m here');
// hide new items while they are loading
var $newElems = $( newElements ).css({ opacity: 0 });
// ensure that images load before adding to masonry layout
$newElems.imagesLoaded(function(){
// show elems now they're ready
$newElems.animate({ opacity: 1 });
$container.isotope( 'appended', $newElems, true );
});
}
);
});
});
这里的容器div位于main.jsp
中<div id="container" class="transitions-enabled infinite-scroll clearfix centered">
<%@ include file="/incl.jsp" %>
</div>
现在,如果我在这个包含的jsp中不包含infinite-scroll.js,那么浏览器会抛出$ container.infinitescroll不是函数的错误。
为什么我必须在包含的jsp中包含js文件?