Copy codeThe Code is as follows:
Var EasyPager = function (wrap, pageCount, currPage ){
Var d = document
, El = function (tag, inner, click, css ){
Tag = d. createElement (tag );
Inner & (tag. innerHTML = inner );
Click & (tag. onclick = click );
Css & (tag. className = css );
Return tag;
}
, Append = function (parent, children, child ){
Children = []. concat (children );
For (var I = 0, j = children. length; I <j; I ++ ){
Child = children [I];
Child & parent. appendChild (child );
}
Return parent;
}
, EasyFn = function (n) {return function () {EasyPager (wrap, pageCount, n )}}
, Box = el ("div"), firstPage, prevPage, lastPage, nextPage, startNum, endNum, pages = [];
CurrPage! = 1 & (firstPage = el ("span", "<", easyFn (1), prevPage = el ("span", "<", easyFn (currPage-1 )));
CurrPage! = PageCount & (lastPage = el ("span", ">", easyFn (pageCount), nextPage = el ("span", "> ", easyFn (currPage + 1 )));
(PageCount <= 10 )? (StartNum = 1, endNum = pageCount): (startNum = currPage-4, endNum = currPage + 5, (currPage <= 5) & (startNum = 1, endNum = 10 ), (currPage >=pageCount-5) & (endNum = pageCount, startNum = pageCount-10 + 1 ));
For (var I = startNum; I <= endNum; I ++) pages. push (el ("span", I, easyFn (I), I = currPage? "CurrSpan": null ))
Append (wrap. innerHTML = "", wrap), append (box, [firstPage, prevPage]. concat (pages). concat (nextPage, lastPage )));
};