最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery Pagination Plugin - Stack Overflow

programmeradmin3浏览0评论

Hopefully this is something that will be easy to remedy. I'm having a bit of an issue understanding the jQuery Pagination plugin.

Essentially, all I am trying to do is load a PHP file, and then paginate the results. I'm attempting to go off their example, but I am not yielding the results I'm looking for.

Here's the JavaScript:

 function pageselectCallback(page_index, jq){
            var new_content = $('#hiddenresult div.result:eq('+page_index+')').clone();
            $('#Searchresult').empty().append(new_content);
            return false;
        }
        function initPagination() {
            var num_entries = $('#hiddenresult div.result').length;
            // Create pagination element
            $("#Pagination").pagination(num_entries, {
                num_edge_entries: 2,
                num_display_entries: 8,
                callback: pageselectCallback,
                items_per_page:3
            });
         }      
        $(document).ready(function(){      
            $('#hiddenresult').load('load.php', null, initPagination);
        });      

Here's my HTML (after the PHP has been loaded):

        <div id="Pagination" class="pagination"> </div>
        <br style="clear:both;" />
        <div id="Searchresult"> </div>

       <div id="hiddenresult" style="display:none;"> 
         <div class="result">Result #1</div>
         <div class="result">Result #2</div>
         <div class="result">Result #3</div>
         <div class="result">Result #4</div>
         <div class="result">Result #5</div>
         <div class="result">Result #6</div>
         <div class="result">Result #7</div>
       </div>

Basically, I am trying to show "3" items per page, but this is not working. I'm assuming that somewhere, I am going to need to create a for loop in my JS, but I'm confused on how to do so. The documentation can be found here.

Hopefully this is something that will be easy to remedy. I'm having a bit of an issue understanding the jQuery Pagination plugin.

Essentially, all I am trying to do is load a PHP file, and then paginate the results. I'm attempting to go off their example, but I am not yielding the results I'm looking for.

Here's the JavaScript:

 function pageselectCallback(page_index, jq){
            var new_content = $('#hiddenresult div.result:eq('+page_index+')').clone();
            $('#Searchresult').empty().append(new_content);
            return false;
        }
        function initPagination() {
            var num_entries = $('#hiddenresult div.result').length;
            // Create pagination element
            $("#Pagination").pagination(num_entries, {
                num_edge_entries: 2,
                num_display_entries: 8,
                callback: pageselectCallback,
                items_per_page:3
            });
         }      
        $(document).ready(function(){      
            $('#hiddenresult').load('load.php', null, initPagination);
        });      

Here's my HTML (after the PHP has been loaded):

        <div id="Pagination" class="pagination"> </div>
        <br style="clear:both;" />
        <div id="Searchresult"> </div>

       <div id="hiddenresult" style="display:none;"> 
         <div class="result">Result #1</div>
         <div class="result">Result #2</div>
         <div class="result">Result #3</div>
         <div class="result">Result #4</div>
         <div class="result">Result #5</div>
         <div class="result">Result #6</div>
         <div class="result">Result #7</div>
       </div>

Basically, I am trying to show "3" items per page, but this is not working. I'm assuming that somewhere, I am going to need to create a for loop in my JS, but I'm confused on how to do so. The documentation can be found here.

Share Improve this question edited Nov 4, 2011 at 18:10 Nightfirecat 11.6k6 gold badges37 silver badges53 bronze badges asked Oct 6, 2009 at 1:13 DodinasDodinas 6,80522 gold badges78 silver badges109 bronze badges 1
  • Hey men I have same issues as yours But i tried doing all script here but i've made it through Hope this help to your problem bit.ly/free-pagination it's only custom scripting not plugsin but really useful – Mary Daisy Sanchez Commented Mar 22, 2011 at 0:12
Add a comment  | 

1 Answer 1

Reset to default 18

You don't even need to use a for loop, just use jQuery's slice() method and a bit of math.

I've hosted a working demo on JS Bin: http://jsbin.com/upuwe (Editable via http://jsbin.com/upuwe/edit)

Here's the modified code:

var pagination_options = {
  num_edge_entries: 2,
  num_display_entries: 8,
  callback: pageselectCallback,
  items_per_page:3
}
function pageselectCallback(page_index, jq){
  var items_per_page = pagination_options.items_per_page;
  var offset = page_index * items_per_page;
  var new_content = $('#hiddenresult div.result').slice(offset, offset + items_per_page).clone();
  $('#Searchresult').empty().append(new_content);
  return false;
}
function initPagination() {
  var num_entries = $('#hiddenresult div.result').length;
  // Create pagination element
  $("#Pagination").pagination(num_entries, pagination_options);
}
发布评论

评论列表(0)

  1. 暂无评论