您好,登錄后才能下訂單哦!
這篇文章主要介紹了thinkPHP框架如何添加js事件的分頁(yè)類customPage.class.php,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
具體如下:
用于ajax動(dòng)態(tài)加載數(shù)據(jù)的分頁(yè)類,分頁(yè)事件可以動(dòng)態(tài)添加,去除了a鏈接中的href地址。
<?php // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK IT ] // +---------------------------------------------------------------------- // | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- // | Author: 麥當(dāng)苗兒 <zuojiazi@vip.qq.com> <http://www.zjzit.cn> // +---------------------------------------------------------------------- namespace Think; class customPage{ public $firstRow; // 起始行數(shù) public $listRows; // 列表每頁(yè)顯示行數(shù) public $parameter; // 分頁(yè)跳轉(zhuǎn)時(shí)要帶的參數(shù) public $totalRows; // 總行數(shù) public $totalPages; // 分頁(yè)總頁(yè)面數(shù) public $rollPage = 6;// 分頁(yè)欄每頁(yè)顯示的頁(yè)數(shù) public $lastSuffix = true; // 最后一頁(yè)是否顯示總頁(yè)數(shù) private $p = 'p'; //分頁(yè)參數(shù)名 private $url = ''; //當(dāng)前鏈接URL private $nowPage = 1; // 分頁(yè)顯示定制 private $config = array( 'header' => '<span class="rows">共 %TOTAL_ROW% 條記錄</span>', 'prev' => '上一頁(yè)', 'next' => '下一頁(yè)', 'first' => '1...', 'last' => '...%TOTAL_PAGE%', 'theme' => '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%', ); /** * 架構(gòu)函數(shù) * @param array $totalRows 總的記錄數(shù) * @param array $listRows 每頁(yè)顯示記錄數(shù) * @param array $parameter 分頁(yè)跳轉(zhuǎn)的參數(shù) */ public function __construct($totalRows, $listRows=20, $parameter = array()) { C('VAR_PAGE') && $this->p = C('VAR_PAGE'); //設(shè)置分頁(yè)參數(shù)名稱 /* 基礎(chǔ)設(shè)置 */ $this->totalRows = $totalRows; //設(shè)置總記錄數(shù) $this->listRows = $listRows; //設(shè)置每頁(yè)顯示行數(shù) $this->parameter = empty($parameter) ? $_GET : $parameter; $this->nowPage = empty($_GET[$this->p]) ? 1 : intval($_GET[$this->p]); $this->totalPages = ceil($this->totalRows / $this->listRows); //總頁(yè)數(shù) if ($this->nowPage>$this->totalPages) { $this->nowPage = $this->totalPages ; } $this->nowPage = $this->nowPage>0 ? $this->nowPage : 1; $this->firstRow = $this->listRows * ($this->nowPage - 1); } /** * 定制分頁(yè)鏈接設(shè)置 * @param string $name 設(shè)置名稱 * @param string $value 設(shè)置值 */ public function setConfig($name,$value) { if(isset($this->config[$name])) { $this->config[$name] = $value; } } /** * 生成鏈接URL * @param integer $page 頁(yè)碼 * @return string */ private function url($page){ return str_replace(urlencode('[PAGE]'), $page, $this->url); } /** * 組裝分頁(yè)鏈接 * @return string */ public function show() { if(0 == $this->totalRows) return ''; /* 生成URL */ $this->parameter[$this->p] = '[PAGE]'; $this->url = U(ACTION_NAME, $this->parameter); /* 計(jì)算分頁(yè)信息 */ if(!empty($this->totalPages) && $this->nowPage > $this->totalPages) { $this->nowPage = $this->totalPages; } /* 計(jì)算分頁(yè)臨時(shí)變量 */ $now_cool_page = $this->rollPage/2; $now_cool_page_ceil = ceil($now_cool_page); $this->lastSuffix && $this->config['last'] = $this->totalPages; //上一頁(yè) $up_row = $this->nowPage - 1; $up_page = $up_row > 0 ? '<a class="shang" id="'.$up_row.'"href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >上一頁(yè)</a>' : ''; //下一頁(yè) $down_row = $this->nowPage + 1; $down_page = ($down_row <= $this->totalPages) ? '<a class="xia" id="'.$down_row.'" href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >下一頁(yè)</a>' : ''; //第一頁(yè) $the_first = ''; if($this->totalPages > $this->rollPage && ($this->nowPage - $now_cool_page) >= 1){ $the_first = '<a class="first" id="1" href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >第一頁(yè)</a>'; } //最后一頁(yè) $the_end = ''; //if($this->totalPages > $this->rollPage && ($this->nowPage + $now_cool_page) < $this->totalPages){ if($this->totalPages > $this->rollPage && ($this->nowPage + $now_cool_page) < $this->totalPages){ $the_end = '<a class="end" id="'.$this->totalRows.'" href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >最后一頁(yè)</a>'; } for($i = 1; $i <= $this->rollPage; $i++){ if(($this->nowPage - $now_cool_page) <= 0 ){ $page = $i; }elseif(($this->nowPage + $now_cool_page - 1) >= $this->totalPages){ $page = $this->totalPages - $this->rollPage + $i; }else{ $page = $this->nowPage - $now_cool_page_ceil + $i; } if($page > 0 && $page != $this->nowPage){ if($page <= $this->totalPages){ $link_page .= ('<li id="'.$page.'">'.$page.'</li>'); }else{ break; } }else{ if($page > 0 && $this->totalPages != 1){ $link_page .= ('<li id="now" id="'.$page.'" class="current">'.$page.'</li>'); } } } if (!empty($link_page)) $link_page = '<ul id="list">'.$link_page.'</ul>'; //替換分頁(yè)內(nèi)容 $page_str = str_replace( array('%HEADER%', '%NOW_PAGE%', '%UP_PAGE%', '%DOWN_PAGE%', '%FIRST%', '%LINK_PAGE%', '%END%', '%TOTAL_ROW%', '%TOTAL_PAGE%'), array($this->config['header'], $this->nowPage, $up_page, $down_page, $the_first, $link_page, $the_end, $this->totalRows, $this->totalPages), $this->config['theme']); $page_str = trim($page_str); if(!empty($page_str)) $page_str .= '<p></p><input value="" type="text"><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="go" class="go">跳轉(zhuǎn)</a>'; return $page_str; } }
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“thinkPHP框架如何添加js事件的分頁(yè)類customPage.class.php”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。