javascript - 新手在项目中模仿sg的分页器. 求指点
黄舟
黄舟 2017-04-10 15:36:39
[JavaScript讨论组]
<?php if($countPage > 1):?>
<p class="pagination-1 pagination">
    <p class="nextPrev-1">
        <ul style="overflow:hidden;">
            <?php if($currentPage > 1):?><li><a href="<?php echo query_url_build('p', $prev)?>">上一页</a></li><?php endif;?>
            <?php if($currentPage >= 5 && $countPage >= $currentPage):?>
                <li><a href="<?php echo query_url_build('p',1)?>">1</a></li>
                <li>...</li>
            <?php endif;?>
            <?php
                $count = ($countPage < 5 ? $countPage : '') ? $countPage : 5;
                for($i = 0; $i < $count; $i++):
                    $index = 0; 
                if($currentPage/5 >= 1){
                    $index = (($currentPage-5)%3 == 0) ? ($currentPage-5)/3 + 1 : floor(($currentPage-5)/3 + 1);
                    }
                $number = 3 * $index + $i + 1;
                ?>
                <li class="<?php echo ((@$_GET['p'] == $number) || (empty($_GET['p'])&&$number==1)) ? 'currentPage' : '';?>">
                    <a href="<?php echo query_url_build('p', $number)?>"><?php echo $number;?></a>
                </li>
            <?php if($number == $countPage){break;} endfor;?>
            <?php if($countPage !== (int)$number):?><li><a>...</a></li><?php endif;?>
            <li><a href="<?php echo query_url_build('p', $next)?>">下一页</a></li>
            <li><a href="<?php echo query_url_build('p', $countPage)?>">末页</a></li>
        </ul>
    </p>
</p>
<?php endif;?>

我只拿到了四条数据,当前页,总页,上一页,下一页;
有没有别的写法 , 我想我这种很低劣吧

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

全部回复(1)
怪我咯

使用Laravel做分页的输出,可以一行代码搞定,很优雅!具体参照它的API

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号