▼resultクラスを持つ要素の数に応じてページネーションを生成します。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="ja" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="imagetoolbar" content="no" /> <title>jQuery Pagination Plugin | 設置サンプル</title> <link rel="stylesheet" type="text/css" href="/content/lib/global.css" /> <!-- JS --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="/content/lib/jquery/jquery.pagination.js"></script> <script type="text/javascript"> $(function() { function pageselectCallback(page_index, jq){ var new_content = $('#hiddenresult div.result:eq('+page_index+')').clone(); $('#res').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:1 }); } $(function(){ initPagination(); }); }); </script> <!-- CSS --> <style type="text/css"> .pagination { margin:0 0 5px 0; padding:0; height:2.5em; } .pagination a { text-decoration:none; border:solid 1px darkorange; color:darkorange; } .pagination a, .pagination span { font-weight:bold; display:block; float:left; margin:0 5px 0 0; padding:.3em .5em; } .pagination .current { background:darkorange; color:#fff; border:solid 1px darkorange; } .pagination .current.prev, .pagination .current.next { color:#999; border-color:#999; background:#fff; } #res { margin:0; padding:0 10px; border:solid 1px #ccc; background:#fff; width:300px; clear:both; } </style> <link rel="stylesheet" type="text/css" href="/common/css/example.css"></head> <body id='example3' class='example'><div class="ads" style="margin:32px auto;text-align:center;"></div><h1 class='h'><a href='/'>PHP & JavaScript Room</a> :: 設置サンプル</h1> <h3 class='h'>実行結果</h3> <div id="wrap"> <h1><a href='http://plugins.jquery.com/project/pagination'>jQuery Pagination Plugin</a></h1> <p>▼resultクラスを持つ要素の数に応じてページネーションを生成します。</p> <!-- CODE --> <div id="Pagination" class="pagination"><!-- ページネーション表示 --></div> <div id="res"><!-- コンテンツ表示領域 --></div> <!-- Container element for all the Elements that are to be paginated --> <div id="hiddenresult" style="display:none;"> <div class="result"> <p>コンテンツ 1</p> <p>コンテンツ 1</p> <p>コンテンツ 1</p> </div> <div class="result"> <p>コンテンツ 2</p> <p>コンテンツ 2</p> <p>コンテンツ 2</p> </div> <div class="result"> <p>コンテンツ 3</p> <p>コンテンツ 3</p> <p>コンテンツ 3</p> </div> <div class="result"> <p>コンテンツ 4</p> <p>コンテンツ 4</p> <p>コンテンツ 4</p> </div> <div class="result"> <p>コンテンツ 5</p> <p>コンテンツ 5</p> <p>コンテンツ 5</p> </div> </div> <!-- CODE / --> </div> </body> </html>