设为首页 加入收藏

TOP

一个分页效果ruby版可作为面试题吧(一)
2019-08-15 00:10:09 】 浏览:201
Tags:一个分 效果 ruby 作为 试题

文章转载自:http://www.pythonheidong.com/blog/article/2186/

#coding:utf-8
total_pages=11
current_page=10
a=(1..total_pages).to_a
  #<div class="page_box"><span><font>&laquo;首页</font></span><span><font>&#173;上一页</font></span>
#<span id="page_on"><font>1</font></span>
#<span><a href="" >2</a></span>
#<span><a href="" >3</a></span>
#<span><a href="" >4</a></span>
#<span><a href="" >5</a></span>
#<span><a href="" >...</a></span>
#<span><a href="" >11</a></span>
#<span><a href="">&#173;下一页</a></span>
#<span><a href="" >&#173;尾页&raquo;</a></span>
#<span><font>1/共11页</font></span>
#</div>
#r=[]
#if current_page-5>0
#  r<<"1"
#  r<<"..."+(current_page-3).to_s
#  r<<current_page-2
#  r<<current_page-1
#  r<<current_page
#  if current_page+1<=total_pages
#    r<<current_page+1
#  end
#  if current_page+2<==total_pages
#    r<<current_page+2
#  end
#else
#  r.concat((1...current_page).to_a)
#end
#r<<current_page
#if current_page+5<=total_pages
#  r<<current_page+1
#  r<<current_page+2
#  r<<"..."+(current_page+3).to_s
#else
#  r.concat(((current_page+1)..total_pages).to_a)
#end
#
#
#
#puts r
#r=[]
#r<<current_page
#if current_page-2>0
#  r.unshift current_page-1
#  
#end
#if current_page-5>0 and current_page+2<=total_pages
#  a[1..
#end
#puts a
r=[]
if total_pages<=6
  r.concat((1..total_pages).to_a)
else
  if current_page-5>0
    if current_page+2<=total_pages
      a.delete_if{|x| x< current_page-2}
    elsif current_page+1<=total_pages
      a.delete_if{|x| x<current_page-3}
    elsif current_page<=total_pages
      a.delete_if{|x| x<current_page-4}
    end
  end
  if current_page+5>0
    if current_page-2>0
      a.delete_if{|x| x >current_page+2}
    elsif current_page-1>0
      a.delete_if{|x| x>current_page+3}
    elsif current_page>0
      a.delete_if{|x| x>current_page+4}
    end
  end
end
if a.first!=1
  a.unshift "..."
  a.unshift 1
end
if a.last!=total_pages
  a&l
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇day011_步入百万年薪的第十一天—.. 下一篇循序渐进掌握递归正则表达式

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目