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

WBOY
풀어 주다: 2016-06-06 20:30:41
원래의
1187명이 탐색했습니다.

<code><?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%20echo%20query_url_build('p',%20%24prev)?>">上一页</a></li>
<?php endif;?>
            <?php if($currentPage >= 5 && $countPage >= $currentPage):?>
                <li><a href="<?php%20echo%20query_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%20echo%20query_url_build('p',%20%24number)?>"><?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%20echo%20query_url_build('p',%20%24next)?>">下一页</a></li>
            <li><a href="<?php%20echo%20query_url_build('p',%20%24countPage)?>">末页</a></li>
        </ul>
    </div>
</div>
<?php endif;?>
</code>
로그인 후 복사
로그인 후 복사

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

回复内容:

<code><?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%20echo%20query_url_build('p',%20%24prev)?>">上一页</a></li>
<?php endif;?>
            <?php if($currentPage >= 5 && $countPage >= $currentPage):?>
                <li><a href="<?php%20echo%20query_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%20echo%20query_url_build('p',%20%24number)?>"><?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%20echo%20query_url_build('p',%20%24next)?>">下一页</a></li>
            <li><a href="<?php%20echo%20query_url_build('p',%20%24countPage)?>">末页</a></li>
        </ul>
    </div>
</div>
<?php endif;?>
</code>
로그인 후 복사
로그인 후 복사

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

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

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!