pagination.js
2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* 生成换页组件
*
* @param page 总的页数
* @param currentPage 当前页序号
* @returns {string} 生成换页组件的innerHTML
*/
function genaratePagination(pageCount, currentPage, functionName) {
var isNeedLeft3Point = false;
var isNeedRightPoint = false;
var left;
var right;
var innerHTML = "";
innerHTML += "<div>";
innerHTML += "<ul class='pagination pagination-split mt5 pull-right' style='margin:5px'>";
if(pageCount <= 10) {
left = 0;
right = pageCount;
} else {
if (currentPage < 5) {
left = 0;
right =10;
isNeedRightPoint = true;
} else if (currentPage >= pageCount - 5) {
left = pageCount - 10;
right = pageCount;
isNeedLeft3Point = true;
} else {
left = currentPage - 4;
right = Number(currentPage) + Number(6);
isNeedRightPoint = true;
isNeedLeft3Point = true;
}
}
//生成向前翻页按钮
if(currentPage == 0) {
innerHTML += "<li class='disabled'><a><i class='fa fa-angle-double-left'></i></a>";
innerHTML += "<li class='disabled'><a><i class='fa fa-angle-left'></i></a>";
} else {
innerHTML += "<li><a href=\"javascript:" + functionName + "(\'"+ "FIRST_PAGE" +"\')\"><i class='fa fa-angle-double-left'></i></a>";
innerHTML += "<li><a href=\"javascript:" + functionName + "(\'"+ "LEFT_PAGE" +"\')\"><i class='fa fa-angle-left'></i></a></li>";
}
if(isNeedLeft3Point) {
innerHTML += "<li class='disabled'>...<li>";
}
//生成中间页翻页按钮
for(var i = left; i < right; i ++) {
if(i == currentPage) {
var page = Number(i) + 1;
innerHTML += "<li class='active'><a href=\"javascript:" + functionName + "(\'"+ i +"\')\">" + page + "</a></li>";
} else {
var page = Number(i) + 1;
innerHTML += "<li><a href=\"javascript:" + functionName + "(\'"+ i +"\')\">" + page + "</a></li>";
}
}
//向后翻页按钮翻页按钮
if (isNeedRightPoint) {
innerHTML += "<li class='disabled'>...<li>";
}
if (currentPage == pageCount - 1) {
innerHTML += "<li class='disabled'><a ><i class='fa fa-angle-right'></i></a></li>";
innerHTML += "<li class='disabled'><a ><i class='fa fa-angle-double-right'></i></a></li>";
} else {
innerHTML += "<li><a href=\"javascript:" + functionName + "(\'"+ "RIGHT_PAGE" +"\')\"><i class='fa fa-angle-right'></i></a></li>";
innerHTML += "<li><a href=\"javascript:" + functionName + "(\'"+ "LAST_PAGE" +"\')\"><i class='fa fa-angle-double-right'></i></a></li>";
}
return innerHTML;
}