Generate page numbers using javascript/jquery?

后端 未结 4 1967
广开言路
广开言路 2020-12-31 20:45

How to generate page numbers like the below using javascript/jquery?

If the 5 th page is selected i have to show 3,4 and 6,7 and also 1,last page with prev,next... A

4条回答
  •  一个人的身影
    2020-12-31 21:44

    yeah @SLaks is right. nothing too crazy here. You will have 2 variables currentPageNumber and lastPageNumber.

    $("div.paginator").append("prev");
    $("div.paginator").append("1");
    
    for (x = (currentPageNumber - 2; x <= (currentPageNumber + 2); x++) {
        $("div.paginator").append(""+ x +"");
    } 
    
    $("div.paginator").append(""+ lastPageNumber +"");
    $("div.paginator").append("next");
    
    // you could apply styles to and a tag in the div.paginator
    // you could apply a special class to the a tag that matches the currentPageNumber 
    // you can also bind some click events to each a tag and use the $(this).text() to grab the number of the page to go to
    

提交回复
热议问题