ajax数据获取分页

推荐使用,等更新

		var pageSize=20; 
		var curPage=0; 
		var lastPage; 
    	var direct=0; 
    	var len;
    	var page; 
    	var begin;
    	var end;
    		$(document).ready(function display(){   
                len =$("#mytable tr").length - 1;   
                page=len % pageSize==0 ? len/pageSize : Math.floor(len/pageSize)+1;
                // alert("page==="+page);
                curPage=1;   
                displayPage(1);
 
                document.getElementById("btn0").innerHTML="当前 " + curPage + "/" + page + " 页    每页 "; 
                document.getElementById("sjzl").innerHTML="数据总量 " + len + "";   
                document.getElementById("pageSize").value = pageSize;
 
                $("#btn1").click(function firstPage(){ 
                    curPage=1;
                    direct = 0;
                    displayPage();
                });
                $("#btn2").click(function frontPage(){  
                    direct=-1;
                    displayPage();
                });
                $("#btn3").click(function nextPage(){ 
                    direct=1;
                    displayPage();
                });
                $("#btn4").click(function lastPage(){
                    curPage=page;
                    direct = 0;
                    displayPage();
                });
                $("#btn5").click(function changePage(){ 
                    curPage=document.getElementById("changePage").value * 1;
                    if (!/^[1-9]\d*$/.test(curPage)) {
                        alert("请输入正整数");
                        return ;
                    }
                    if (curPage > page) {
                        alert("超出数据页面");
                        return ;
                    }
                    direct = 0;
                    displayPage();
                });
 
                $("#pageSizeSet").click(function setPageSize(){ 
                    pageSize = document.getElementById("pageSize").value; 
                    if (!/^[1-9]\d*$/.test(pageSize)) {
                        alert("请输入正整数");
                        return ;
                    }
                    len =$("#mytable tr").length - 1;
                    page=len % pageSize==0 ? len/pageSize : Math.floor(len/pageSize)+1;
                    curPage=1;     
                     direct=0;   
                     firstPage();
                });
            });
 
            function displayPage(){
                if(curPage <=1 && direct==-1){
                    direct=0;
                    alert("已经是第一页了");
                    return;
                } else if (curPage >= page && direct==1) {
                    direct=0;
                    alert("已经是最后一页了");
                    return ;
                }
                lastPage = curPage;
 
                if (len > pageSize) {
                    curPage = ((curPage + direct + len) % len);
                } else {
                    curPage = 1;
                }
 
                document.getElementById("btn0").innerHTML="当前 " + curPage + "/" + page + " 页    每页 "; 
                begin=(curPage-1)*pageSize + 1;
                end = begin + 1*pageSize - 1;
 
                
                if(end > len ) end=len;
                $("#mytable tr").hide(); 
                $("#mytable tr").each(function(i){ 
                    if((i>=begin && i<=end) || i==0 )
                        $(this).show();
                });
             }



		for( j = 0; j < list.length; j++ ) {
			if(!list[j])
				return;
			mac = list[j].mac;
			rssi = list[j].rssi;
			uptime = list[j].onlinetime;
			apmac = list[j].apmac;
			ssid = list[j].ssid;
			txrate = list[j].txrate;
			rxrate = list[j].rxrate;
			rxrate = list[j].rxrate;
			apname = list[j].apname;
			
			if(list[j].onlinetime) {
				var uptime;
				var hour;
				var min;
				var sec;
				var onlinetime = list[j].onlinetime;
				
				hour = parseInt(onlinetime/3600);
				onlinetime = onlinetime % 3600;
				min = parseInt(onlinetime/60);
				sec = onlinetime%60;
				if(hour > 0)
					uptime = hour+ "<%:h%> " + min + "<%:m%>" + sec + "<%:s%>";
				else if(min > 0)
					uptime = min + "<%:m%>" + sec + "<%:s%>";
				else
					uptime = sec + "<%:s%>";			
			}
			
			if(list[j].ifaceid % 2 == 0)
				ifaceid = "2.4G";
			else
				ifaceid = "5G";			

			tbl.appendChild(E('tr'.format(j), [
					E('td', mac),
					E('td', ssid),
					E('td', rssi),
					E('td', txrate + "/" + rxrate),
					E('td', uptime),
					E('td', apname),
					E('td', apmac),
					E('td', ifaceid),
					]));
		}
		
		$('.ac-summary').empty();
		$('.ac-summary').append('<em><span><%:Total Users%>:</span><span>'+stanum+'</span></em>');	
	

	 
	 jQuery("#mytable").tablesorter({  
		 headers: {  
			0: { sorter:true},  
			 
		 }  
	 });  
	 

	}

<table id="mytable" class="tablesorter tablesorter-default">
		<thead><tr>
			<th><%:STA MAC%></th>
			<th><%:SSID%></th>
			<th><%:RSSI(dBm)%></th>
			<th><%:Tx/Rx Rate%></th>
			<th><%:Online Time%></th>
			<th><%:AP Name%></th>
			<th><%:AP MAC%></th>
			<th><%:2.4G/5G%></th>
	</tr>
	</thead>
	<tbody id="sta_status_table" style="color: #525f7f;">	
	</tbody>
</table>
	<div align="center" style="font-size: 14px;padding-top: 10px;" class="astyle">
		<a id="btn0"></a>
		<input id="pageSize" type="text" size="1" maxlength="2" value="getDefaultValue()" style="width:50px;height:30px"/>
		<a></a> 
		<a href="#" id="pageSizeSet">设置</a> 
		<a id="sjzl"></a> 
		<a  href="#" id="btn1">首页</a>
		<a  href="#" id="btn2">上一页</a>
		<a  href="#" id="btn3">下一页</a>
		<a  href="#" id="btn4">尾页</a> 
		<a>转到 </a>
		<input id="changePage" type="text" size="1" maxlength="4" style="width:50px;height:30px"/>
		<a></a>
		<a  href="#" id="btn5">跳转</a>
	
	</div>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值