首页 > 后端开发 > php教程 > PHP分类页

PHP分类页

WBOY
发布: 2016-06-06 20:13:00
原创
911 人浏览过

<code><?php class Pagination_lib{
    //总页数
    public $all = 10;
    //当前页
    public $now = 1;
    //选择器
    public $seletor = "main_in_main";
    //跳转地址
    public $url = '';
    public function init($all = 10,$now = 1,$seletor = "main_in_main",$url = ''){
        $this->all = $all;
        $this->now = $now;
        $this->seletor = $seletor;
        $this->url = $url;
        if($this->now > $this->all ){
            $this->all = 0;
        }
        if($this->now now = 1;
        }
    }
    public function display(){
        $str = "<ul class="pagination">";
//         if($this->all == 0){
//             $str.="<div class="no_record">没有相关记录</div>";
//         }else{
            if($this->all == 1){
                $str.="<li class="active"><a href="javascript:;" data-href="1">1<span class="sr-only">(current)</span></a></li>";
            }else{
                if($this->now > 1 && $this->now <a href="javascript:;" data-href="1">第一页</a>
                            <li><a href="javascript:;" data-href='".($this->now-1)."'>«</a></li>";
                    for($i = 1; $i now; $i++) {
                        $str.="<li><a href="javascript:;" data-href="{$i}">{$i}</a></li>";
                    }
                }elseif($this->now >= 6){
                    $str.="<li><a href="javascript:;" data-href="1">第一页</a></li>
                    <li><a href="javascript:;" data-href=".($this->now-1).">«</a></li>
                    <li><a href="javascript:void(0)">...</a></li>";
                    for($i = $this->now-4; $i now; $i++) {
                        $str.="<li><a href="javascript:;" data-href="{$i}">{$i}</a></li>";
                    }
                }
                $str.="<li class="active"><a href="javascript:void(0)">{$this->now}<span class="sr-only">(current)</span></a></li>";
                if($this->all - $this->now > 4) {
                    for($i = $this->now + 1; $i now + 4; $i++) {
                        $str.="<li><a href="javascript:;" data-href="{$i}">{$i}</a></li>";
                    }
                    $str.="
                    <li><a href="javascript:void(0)">...</a></li>
                    <li><a href="javascript:;" data-href='".($this->now+1)."'>»</a></li>
                    <li><a href="javascript:;" data-href="{$this->all}">最后页</a></li>
                    ";
                }elseif($this->all - $this->now >= 1){
                    for($i = $this->now + 1; $i all; $i++) {
                        $str.="<li><a href="javascript:;" data-href="{$i}">{$i}</a></li>";
                    }
                    $str.="<li><a href="javascript:;" data-href='".($this->now+1)."'>»</a></li>
                            <li><a href="javascript:;" data-href="{$this->all}">最后页</a></li>";
                }
            }
            $str.="<span class="goto"> 跳到<input type="text" class="goto-input" id="goto-input" maxlength="5" value="{$this->now}">页
                    <a href="javascript:void(0)" class="btn btn-default btn-sm goto-btn" id="goto-btn">GO</a>
                    </span>
                    </ul>
                ";
            $str.= "<style>
.pagination {
    width: 100%;
    margin: 0px 0px;
}
.pagination .goto {
  position: relative;
  float: left;
  height: 34px;
  padding: 6px 12px;
  line-height: 1.42857143;
  margin-left: -1px;
  width: 200px;
  padding-left: 0;
  margin-left: -4px;
  margin-top: -4px;
}
.pagination  .goto-input{
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  height: 32px;
}
.pagination .goto-btn{
  margin-top: -3px;
}            
                    </style>";
//         }
                    
        return $str;
    }
}


?></code>
登录后复制
登录后复制

我想问问这种分页什么意思 怎么有js代码

回复内容:

<code><?php class Pagination_lib{
    //总页数
    public $all = 10;
    //当前页
    public $now = 1;
    //选择器
    public $seletor = "main_in_main";
    //跳转地址
    public $url = '';
    public function init($all = 10,$now = 1,$seletor = "main_in_main",$url = ''){
        $this->all = $all;
        $this->now = $now;
        $this->seletor = $seletor;
        $this->url = $url;
        if($this->now > $this->all ){
            $this->all = 0;
        }
        if($this->now now = 1;
        }
    }
    public function display(){
        $str = "<ul class="pagination">";
//         if($this->all == 0){
//             $str.="<div class="no_record">没有相关记录</div>";
//         }else{
            if($this->all == 1){
                $str.="<li class="active"><a href="javascript:;" data-href="1">1<span class="sr-only">(current)</span></a></li>";
            }else{
                if($this->now > 1 && $this->now <a href="javascript:;" data-href="1">第一页</a>
                            <li><a href="javascript:;" data-href='".($this->now-1)."'>«</a></li>";
                    for($i = 1; $i now; $i++) {
                        $str.="<li><a href="javascript:;" data-href="{$i}">{$i}</a></li>";
                    }
                }elseif($this->now >= 6){
                    $str.="<li><a href="javascript:;" data-href="1">第一页</a></li>
                    <li><a href="javascript:;" data-href=".($this->now-1).">«</a></li>
                    <li><a href="javascript:void(0)">...</a></li>";
                    for($i = $this->now-4; $i now; $i++) {
                        $str.="<li><a href="javascript:;" data-href="{$i}">{$i}</a></li>";
                    }
                }
                $str.="<li class="active"><a href="javascript:void(0)">{$this->now}<span class="sr-only">(current)</span></a></li>";
                if($this->all - $this->now > 4) {
                    for($i = $this->now + 1; $i now + 4; $i++) {
                        $str.="<li><a href="javascript:;" data-href="{$i}">{$i}</a></li>";
                    }
                    $str.="
                    <li><a href="javascript:void(0)">...</a></li>
                    <li><a href="javascript:;" data-href='".($this->now+1)."'>»</a></li>
                    <li><a href="javascript:;" data-href="{$this->all}">最后页</a></li>
                    ";
                }elseif($this->all - $this->now >= 1){
                    for($i = $this->now + 1; $i all; $i++) {
                        $str.="<li><a href="javascript:;" data-href="{$i}">{$i}</a></li>";
                    }
                    $str.="<li><a href="javascript:;" data-href='".($this->now+1)."'>»</a></li>
                            <li><a href="javascript:;" data-href="{$this->all}">最后页</a></li>";
                }
            }
            $str.="<span class="goto"> 跳到<input type="text" class="goto-input" id="goto-input" maxlength="5" value="{$this->now}">页
                    <a href="javascript:void(0)" class="btn btn-default btn-sm goto-btn" id="goto-btn">GO</a>
                    </span>
                    </ul>
                ";
            $str.= "<style>
.pagination {
    width: 100%;
    margin: 0px 0px;
}
.pagination .goto {
  position: relative;
  float: left;
  height: 34px;
  padding: 6px 12px;
  line-height: 1.42857143;
  margin-left: -1px;
  width: 200px;
  padding-left: 0;
  margin-left: -4px;
  margin-top: -4px;
}
.pagination  .goto-input{
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  height: 32px;
}
.pagination .goto-btn{
  margin-top: -3px;
}            
                    </style>";
//         }
                    
        return $str;
    }
}


?></code>
登录后复制
登录后复制

我想问问这种分页什么意思 怎么有js代码

这个应该是分页类。传入分页数据(一页显示条数,页数,页码等)直接生成HTML代码和分页的数据

与楼上的回答一致... 生成分页好的点击样式直接输出成html页面代码.. 包含样式/点击跳转等...

其实就是图简单,php 直接输出 html,然后页面上就有分页按钮了,但是修改样式的时候就比较不好控制

相关标签:
php
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板