The main purpose of this article is to share with you the specific operation methods of layPage's multi-functional js pagination component for your reference. The specific content is as follows
php part
function index(){ header('Content-Type:text/html;charset=utf-8'); // Get the current page number, default the first page, set the default number of displayed characters per page $nowpage = I('get.page', 1, 'intval'); $limits = 8; // Get the total number of characters $count = M('Article') -> where(array('status'=>array('egt', 0))) -> count(); // Calculate the total page $allpage = ceil($count / $limits); $allpage = intval($allpage); $lists = M('Article') -> where(array('status'=>array('egt', 0))) -> page($nowpage, $limits) // page method pagination-> order('createtime desc') -> select(); // jump paging output $this -> assign('lists', $lists); $this -> assign('allpage', $allpage); $this -> assign('nowpage', $nowpage); $this->display(); /* // ajax paging output $info = array('lists'=>$lists,'allpage'=>$allpage,'nowpage'=>$nowpage); $this->ajaxReturn($info,'json'); */ }layoutpage (new version) in js jump to pagination
// Pagination layout({ cont: 'show_pages', // Pagination container pages: "{$allpage}", // Total number of pages skip: true, // Whether to turn on page jump curr: function(){ var page = "{$nowpage}"; // Current page (get obtained from the background) return page ? page : 1; // Return the current page number value}(), jump: function(e, first){ // Callback after triggering the page (after clicking the page number) if(!first){ // Be sure to add this judgment, otherwise var urls will be refreshed infinitely at the initial stage. nowpage = e.curr; // (page number clicked) urls = urls.replace('pageval',nowpage); // Replace link style and page number window.location.href = urls; } } });layoutpage (new version) ajax pagination in js
function demo(curr){ $.getJSON("{:U('article/index')}", { page: curr //The parameters passed to the server are just demonstrations}, function(res){ //The json result returned by the server //The data content in res.lists is processed here, and the html() method is displayed //Off... //The pagination layout({ cont: 'show_pages', //Container pages: res.allpage, //Total number of pages (backend) curr: res.nowpage, //The current page (get obtained from the background) jump: function(obj, first){ //The callback after the pagination is triggered (after clicking on the page number) if(!first){ //Click the page jump to trigger the function itself and pass the current page: obj.curr demo(obj.curr); // (page number clicked) } } }); }); }); // Initialize and run demo();The above is all about this article. I hope it will be helpful for everyone to learn the pagination component layoutPage.