您好我正在尝试获取内容区域中当前显示的帖子数量。当前显示的帖子数量为3,但是当我检查长度时,它返回1。
$(document).on("click", ".load-more", function() {
var currentPost = $('#postlist');
loadMore = currentPost.parent().find('.load-more');
initialPostcount = currentPost.length;
console.log(initialPostcount);
})
<!-- Page: Blog Posts -->
<div id="blogposts" data-role="page">
<div data-role="header" data-position="fixed">
<h2>My Blog Posts</h2>
</div><!-- header -->
<div data-role="content">
<ul data-filter="true" data-filter-placeholder='Search blog posts...' id="postlist"> </ul><!-- content -->
</div>
<div class="load-more">Load More Posts...</div>
<div id='loader'><img src="css/images/loader.gif"/></div>
</div><!-- page -->
答案 0 :(得分:1)
您的帖子位于ul
列表中。你需要计算li
[]下ul#postlist
的长度,假设每个li
是一个帖子]
<ul data-filter="true" data-filter-placeholder='Search blog posts...' id="postlist"> </ul><!-- content -->
更改$('#postlist')
var currentPost = $('#postlist');
带
var currentPost = $('#postlist li');
$('#postlist li')
正是您要找的,