计算Div中当前帖子的数量

时间:2013-10-27 06:02:54

标签: javascript jquery jquery-mobile

您好我正在尝试获取内容区域中当前显示的帖子数量。当前显示的帖子数量为3,但是当我检查长度时,它返回1。

$(document).on("click", ".load-more", function() {

    var currentPost = $('#postlist');
    loadMore = currentPost.parent().find('.load-more');
    initialPostcount = currentPost.length;
    console.log(initialPostcount);

})
  1. 最新帖子列表:
  2. enter image description here

    1. 检查要素:
    2. enter image description here

      <!-- 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 -->
      

1 个答案:

答案 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')正是您要找的,