<!DOCTYPE html
>
<html lang
="en">
<head
>
<meta charset
="UTF-8">
<meta name
="viewport" content
="width=device-width, initial-scale=1.0">
<meta http
-equiv
="X-UA-Compatible" content
="ie=edge">
<title
>Document
</title
>
</head
>
<body
>
<p onclick
="paginationFn(arrList,10,2)">123</p
>
<script
>
let arrList
= [1, 4, 5, 6, 34, 34, 67, 895, 2456, 87, 9, 5, 23, 884, 56, 463];
window
.onlick
= arrayGroup(arrList
, 5);
function paginationFn(arrayList
, perPage
, current
) {
let showArray
= []
let startRow
= (current
- 1) * perPage
+ 1
let endRow
= current
* perPage
> arrayList
.length
? arrayList
.length
: current
* perPage
arrayList
.filter((e
, i
) => {
if (i
+ 1 >= startRow
&& i
+ 1 <= endRow
) {
showArray
.push(e
)
}
return showArray
})
console
.log(showArray
)
}
function arrayGroup(list
, num
) {
var result
= new Array(Math
.ceil(list
.length
/ num
))
for (let i
= 0; i
< result
.length
; i
++) {
result
[i
] = new Array();
for (var j
= 0; j
< num
; j
++) {
result
[i
][j
] ? result
[i
][j
] : '';
}
}
list
.forEach((e
, i
) => {
result
[parseInt(i
/ num
)][i
% num
] = list
[i
]
return result
})
console
.log(result
)
}
</script
>
</body
>
</html
>
转载请注明原文地址: https://yun.8miu.com/read-22329.html