您好,登錄后才能下訂單哦!
thinkphp 分頁中間省略號(hào)實(shí)現(xiàn) <?php class Pages{ public $firstRow; // 起始行數(shù) public $listRows; // 列表每頁顯示行數(shù) public $parameter; // 分頁跳轉(zhuǎn)時(shí)要帶的參數(shù) public $totalRows; // 總行數(shù) public $totalPages; // 分頁總頁面數(shù) public $rollPage = 5;// 分頁欄每頁顯示的頁數(shù) public $lastSuffix = true; // 最后一頁是否顯示總頁數(shù) private $p = 'p'; //分頁參數(shù)名 private $url = ''; //當(dāng)前鏈接URL private $nowPage = 1; // 分頁顯示定制 private $config = array( 'header' => '<input type="hidden" id="totalPage" value="%totalPage%"> <span>Go to page:</span> <input type="text" value="1" id="fanyePage" /> <input type="button" name="" id="pagebutton" value="GO" />', 'first' => '首頁', 'prev' => 'Prev Page', 'next' => 'Next Page', 'last' => '末頁', 'theme' => '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%', ); /** * 架構(gòu)函數(shù) * @param array $totalRows 總的記錄數(shù) * @param array $listRows 每頁顯示記錄數(shù) * @param array $parameter 分頁跳轉(zhuǎn)的參數(shù) */ public function __construct($totalRows, $listRows=20, $parameter = array()) { C('VAR_PAGE') && $this->p = C('VAR_PAGE'); //設(shè)置分頁參數(shù)名稱 /* 基礎(chǔ)設(shè)置 */ $this->totalRows = $totalRows; //設(shè)置總記錄數(shù) $this->listRows = $listRows; //設(shè)置每頁顯示行數(shù) $this->totalPages = ceil($this->totalRows/$this->listRows); //總頁數(shù) $this->parameter = empty($parameter) ? $_GET : $parameter; $this->nowPage = empty($_GET[$this->p]) ? 1 : intval($_GET[$this->p]); $this->nowPage = $this->nowPage>0 ? $this->nowPage : 1; $this->firstRow = $this->listRows * ($this->nowPage - 1); if($this->nowPage<1){ $this->nowPage = 1; }elseif(!empty($this->totalPages) && $this->nowPage>$this->totalPages) { $this->nowPage = $this->totalPages; } } /** * 定制分頁鏈接設(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 頁碼 * @return string */ private function url($page){ //dump(urlencode('[PAGE]')); //return str_replace(urlencode('[PAGE]'), $page, $this->url); $url =str_replace(urlencode('[PAGE]'), $page, $this->url); $url = str_replace(".html","",'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"].'/p/'.$page); if($_GET['p']){ $url = str_replace("/p/".$_GET['p']."","",'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"].'/p/'.$page); } $url = str_replace(".html","",$url).'.html'; return $url; } /** * 組裝分頁鏈接 * @return string */ public function show(){ $adjacents=2; if(0 == $this->totalRows) return ''; $this->parameter[$this->p] = '[PAGE]'; $this->url = U(ACTION_NAME, $this->parameter); /* 計(jì)算分頁信息 */ $this->totalPages = ceil($this->totalRows / $this->listRows); //總頁數(shù) if(!empty($this->totalPages) && $this->nowPage > $this->totalPages) { $this->nowPage = $this->totalPages; } //上下翻頁字符串 $upRow = $this->nowPage-1; $downRow = $this->nowPage+1; // 上一頁 if ($upRow>0){ $pages.= "<a href='".$this->url($upRow)."' class='prev'>".$this->config['prev']."</a>"; }else{ $pages.= "<a class='prev current'>".$this->config['prev']."</a>"; } //第一頁 if($this->nowPage>($adjacents+1)) { $pages.= "<a href='".$this->url(1)."'>1</a>"; } // 添加省略號(hào) if($this->nowPage>($adjacents+2)) { $pages.= "<a>...</a>"; } // 12345 $pmin = ($this->nowPage>$adjacents) ? ($this->nowPage-$adjacents) : 1; $pmax = ($this->nowPage<($this->totalPages-$adjacents)) ? ($this->nowPage+$adjacents) : $this->totalPages; for($i=$pmin; $i<=$pmax; $i++) { if($i==$this->nowPage) { $pages.= "<a class='on'>".$i."</a>"; }else{ $pages.= "<a href='".$this->url($i)."'>".$i."</a>"; } } // 添加省略號(hào) if($this->nowPage < ($this->totalPages-$adjacents-1)) { $pages.= "<a>...</a>"; } // 最后一頁 if($this->nowPage<($this->totalPages-$adjacents)) { $pages.= "<a href='".$this->url($this->totalPages)."'>".$this->totalPages."</a>"; } // 下一頁 if ($downRow <= $this->totalPages){ $pages.= "<a href='".$this->url($downRow)."' class='next'>".$this->config['next']."</a>"; }else{ $pages.= "<a class='next current'>".$this->config['next']."</a>"; } $pages.= '<input type="hidden" id="totalPage" value="%totalPage%"> <span>Go to page:</span> <input type="text" value="1" id="fanyePage" /> <input type="button" name="" id="pagebutton" value="GO" />'; return $pages; } } <div class="yPub_fan"> {$page} </div> 分頁跳轉(zhuǎn)方式 <script> $('#pagebutton').click(function(){ <?php $SELF = $_SERVER['REQUEST_URI'];$SELF = str_replace(".html", "",$SELF);?> var totalPage = parseInt($('#totalPage').val()); var fanyePage = parseInt($('#fanyePage').val()); if(!fanyePage){ return false; } if(totalPage<fanyePage){ layer.alert('不能大于總頁數(shù)'); return false; } window.location.href = "<?php echo $SELF?>/p/"+fanyePage; }); </script>
免責(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)容。