上一页 = 5 && $countPage >= $currentPage):?> ">1">
当前位置:Gxlcms > PHP教程 > javascript-新手在项目中模仿sg的分页器.求指点

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

时间:2021-07-01 10:21:17 帮助过:0人阅读

  1. <code><!--?php if($countPage --> 1):?>
  2. <ul style="overflow:hidden;">
  3. <!--?php if($currentPage --> 1):?><li>">上一页</li><!--?php endif;?-->
  4. <!--?php if($currentPage -->= 5 && $countPage >= $currentPage):?>
  5. <li>">1</li>
  6. <li>...</li>
  7. <!--?php endif;?-->
  8. <!--?php
  9. $count = ($countPage < 5 ? $countPage : '') ? $countPage : 5;
  10. for($i = 0; $i < $count; $i++):
  11. $index = 0;
  12. if($currentPage/5 -->= 1){
  13. $index = (($currentPage-5)%3 == 0) ? ($currentPage-5)/3 + 1 : floor(($currentPage-5)/3 + 1);
  14. }
  15. $number = 3 * $index + $i + 1;
  16. ?>
  17. <li class="<?php echo ((@$_GET['p'] == $number) || (empty($_GET['p'])&&$number==1)) ? 'currentPage' : '';?>">
  18. "><!--?php echo $number;?-->
  19. </li>
  20. <!--?php if($number == $countPage){break;} endfor;?-->
  21. <!--?php if($countPage !== (int)$number):?--><li>...</li><!--?php endif;?-->
  22. <li>">下一页</li>
  23. <li>">末页</li>
  24. </ul>
  25. <!--?php endif;?-->
  26. </code>

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

回复内容:

  1. <code><!--?php if($countPage --> 1):?>
  2. <ul style="overflow:hidden;">
  3. <!--?php if($currentPage --> 1):?><li>">上一页</li><!--?php endif;?-->
  4. <!--?php if($currentPage -->= 5 && $countPage >= $currentPage):?>
  5. <li>">1</li>
  6. <li>...</li>
  7. <!--?php endif;?-->
  8. <!--?php
  9. $count = ($countPage < 5 ? $countPage : '') ? $countPage : 5;
  10. for($i = 0; $i < $count; $i++):
  11. $index = 0;
  12. if($currentPage/5 -->= 1){
  13. $index = (($currentPage-5)%3 == 0) ? ($currentPage-5)/3 + 1 : floor(($currentPage-5)/3 + 1);
  14. }
  15. $number = 3 * $index + $i + 1;
  16. ?>
  17. <li class="<?php echo ((@$_GET['p'] == $number) || (empty($_GET['p'])&&$number==1)) ? 'currentPage' : '';?>">
  18. "><!--?php echo $number;?-->
  19. </li>
  20. <!--?php if($number == $countPage){break;} endfor;?-->
  21. <!--?php if($countPage !== (int)$number):?--><li>...</li><!--?php endif;?-->
  22. <li>">下一页</li>
  23. <li>">末页</li>
  24. </ul>
  25. <!--?php endif;?-->
  26. </code>

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

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

人气教程排行