javascript - 新手在项目中模仿sg的分页器. 求指点

php中文网
发布: 2016-06-06 20:30:41
原创
1496人浏览过

<?php if($countPage > 1):?>
<div class="pagination-1 pagination">
    <div 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>
    </div>
</div>
<?php endif;?>
登录后复制

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

回复内容:

<?php if($countPage > 1):?>
<div class="pagination-1 pagination">
    <div 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>
    </div>
</div>
<?php endif;?>
登录后复制

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

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

腾讯智影
腾讯智影

腾讯推出的在线智能视频创作平台

腾讯智影 341
查看详情 腾讯智影
相关标签:
java速学教程(入门到精通)
java速学教程(入门到精通)

java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

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