我做了一个函数,返回分页时显示的数字。我想得到这样的东西(括号是活动站点的唯一显示):
如果第10页
1 2 3 4 5 6 7 8 9 10
如果页数大于10
1 2 3 ... 20 [30] 40 ... 78 79 80
其中[30]是活动页。如果活动页<;3
1 2 [3] 4 ... 20 30 40 ... 78 79 80
等等,我的代码:
count_all - number of all items
items_on_page - items displayed on one page
page - current page
countpages = int(float(count_all+(items_on_page-1))/float(items_on_page))
linkitems = 10
if countpages > (linkitems-1):
countpagesstr = list()
for i in range(1,int(float(linkitems+(2))/float(3))):
countpagesstr += [str(i)]
countpagesstr += ['...']
sr = int(countpages/2)
for i in range(sr-1, sr+1):
countpagesstr += [str(i)]
countpagesstr += ['...']
for i in range(countpages-3, countpages):
countpagesstr += [str(i)]
else:
cp = list()
for c in range(1,countpages+1):
cp.append(str(c))
countpagesstr = cp
return countpagesstr
如何做得更好?你知道吗
你在那里所做的和:
相关问题 更多 >
编程相关推荐