php分页事件

public static function getpageHTML($url, $currentPage, $pageCount, $neighborLength = 3){

        if($pageCount < 2 )
        return "";

        $start = $currentPage  - $neighborLength;
        $end = $currentPage + $neighborLength;

        if($start <= 4){
            $start = 2;
        }

        $start = $start > 1 ? $start : 2;

        $end = 2* $neighborLength - ($start < $currentPage? ($currentPage - $start ) : 0 ) + $currentPage;
        $end = $end < $pageCount ? $end : ( $pageCount - 1 );

        $str = "";
        //上一页
        $str.= $currentPage == 1 ? '<span class="page-start"><b>&lt;</b>上一页</span>' : '<a href="' . str_replace("{page}", $currentPage - 1, $url) . '" class="page-prev"><b>&lt;</b>上一页</a>';

        //第一页
        $str.= $currentPage == 1 ? "" : '<a href="' . str_replace("{page}", 1, $url) . '">1</a>';

        //左邻居
        if( $start != 2 )
        $str.= '<span class="page-break">...</span>';
        for($i = $start; $i < $currentPage; $i++){
            $str.=  '<a href="' . str_replace("{page}", $i, $url) . '">' . $i . '</a>';
        }

        //当前页
        $str.= '<span class="page-this">' . $currentPage . '</span>';

        //右邻居
        for($i = $currentPage + 1; $i < $end + 1; $i++){
            $str.=  '<a href="' . str_replace("{page}", $i, $url) . '">' . $i . '</a>';
        }

        if( $end != $pageCount - 1 )
        $str.= '<span class="page-break">...</span>';

        //最后一页
        $str.= $currentPage != $pageCount  ? '<a href="' . str_replace("{page}", $pageCount, $url) . '">' . $pageCount . '</a>' : '';

        //下一页
        $str.= $currentPage != $pageCount  ? '<a href="' .  str_replace("{page}", $currentPage + 1, $url) . '" class="page-next">下一页<b>&gt;</b></a>' : '<span class="page-end">下一页<b>&gt;</b></span>';

        //输入框跳转
        $str.= '<span class="page-skip"> 到第<input type="text" value="' . $currentPage . '" maxlength="3">页<button value="go" οnclick="var a=parseInt($(this).parent().find(\'input[type=text]\').val(),10);a=(!!a&&a>0&&a<='. $pageCount .')?a:1;window.location.href=\''.str_replace("{page}", '\'+a+\'', $url).'\'" class="button">确定</button></span>';

        return $str;

    }

调用事例:

getpageHTML("/index.php?cid={$categoryId}&page={page}", $currentPage, ceil( $RECORDCount/ $PAGESIZE), (ceil( $RECORDCount / $PAGESIZE) + 1) ),


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值