JS Paging Code

Source: Internet
Author: User

HTML code

<table class= "gridtable" align= "center" valign= "center" id= "Fenye" >
<tr>
<th width=600> Single Head </th>
<th width=600> Single Head </th>
</tr>


@foreach ($data as $_data)
<TR class= "test" style= "Display:none;" >
<TD width=600> First Article </td>
<TD width=600> First Data </td>
</tr>
@endforeach

</table>

JS section, you can customize the modification

<script>

var obj,j;
var page=0;
var nowpage=0;//current Page
var listnum=20;//display <ul> per page
var pageslen;//total Pages
var pagenum=7;//page link Number of links (5)
Onload=function () {
Obj=document.getelementbyid ("Fenye"). Getelementsbyclassname ("test");
J=obj.length

Pageslen=math.ceil (J/listnum);
Uppage (0)
}
function Uppage (p) {
Nowpage=p
Content transformation
for (Var i=0;i<j;i++) {
Obj[i].style.display= "None"
}
For (Var i=p*listnum;i< (p+1) *listnum;i++) {
if (Obj[i]) obj[i].style.display= "Table-row"
}
Paging Link transformation
strs= ' <a href= "# # #" onclick= "uppage (0)" > Home </a> "
var pagenum_2=pagenum%2==0? Math.ceil (PAGENUM/2) +1:math.ceil (PAGENUM/2)
var pagenum_3=pagenum%2==0? Math.ceil (PAGENUM/2): Math.ceil (PAGENUM/2) +1
var strc= "", startpage,endpage;
if (Pagenum>=pageslen) {startpage=0;endpage=pageslen-1}
else if (nowpage<pagenum_2) {startpage=0;endpage=pageslen-1>pagenum? pagenum:pageslen-1}//Home
else {Startpage=nowpage+pagenum_3>=pageslen? Pageslen-pagenum-1: Nowpage-pagenum_2+1;var T=startpage+pagenum;endpage=t>pageslen? Pageslen-1:t}
for (Var i=startpage;i<=endpage;i++) {
if (i==nowpage) strc+= ' <a href= ' # # # "style=" color:red;font-weight:700 "onclick=" uppage (' +i+ ') "> ' + (i+1) + ' < /a> '
else strc+= ' <a href= ' # # # ' onclick= ' uppage (' +i+ ') ' > ' + (i+1) + ' </a> '
}
Stre= ' <a href= ' # # # onclick= ' Uppage (' + (PagesLen-1) + ') ' > Last </a> '
stre2=nowpage+1+ "/" +pageslen+ "page" + "Total" +j+ "bar"
StrE3 = ", Success" +{{$success}}+ "bar, failed <span style= ' color:red;font-weight:700; ' > "+{{$fail}}+" </span> Bar "
document.getElementById ("Changpage"). Innerhtml=strs+strc+stre+stre2+stre3
}

</script>

JS Paging Code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.