什么也不说了,直接上代码: 复制代码 代码如下: String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> 分页 <BR>var tableData = [{"C0":"临夏州_康乐县","C1":190893.39,"C2":24544.65,"AREA_ID":"930013005"},{"C0":"临夏州_永靖县","C1":368900.35,"C2":40592.19,"AREA_ID":"930013006"},{"C0":"兰州市_东岗分局","C1":88.48,"C2":126.4,"AREA_ID":"930013106"},{"C0":"临夏州_临夏县","C1":107337.9,"C2":20612.1,"AREA_ID":"930013008"},{"C0":"临夏州_广河县","C1":69738.07,"C2":34894.44,"AREA_ID":"930013003"},{"C0":"临夏州_和政县","C1":46622.96,"C2":20954.97,"AREA_ID":"930013002"},{"C0":"临夏州_东乡县","C1":96021.84,"C2":16725.63,"AREA_ID":"930013004"},{"C0":"临夏州_临夏市中心","C1":1845311.12,"C2":129478.93,"AREA_ID":"930013001"},{"C0":"天水市_秦州区","C1":0,"C2":0,"AREA_ID":"930013801"},{"C0":"临夏州_积石山","C1":256181.79,"C2":15185.98,"AREA_ID":"930013007"},{"C0":"酒泉_肃州区","C1":264312,"C2":402.6,"AREA_ID":"930013701"}]; <BR>var columns = [{"cid":"C0","ctext":"区县"},{"cid":"C1","ctext":"客户总收入"},{"cid":"C2","ctext":"当月出账费用"}]; <BR>/** <BR>page:页码 <BR>pageSize:每页的记录条数 <BR>此方法除了传入page和pageSize之外,还应知道的有三个参数: <BR>一、表的全部数据,json串格式,可通过action查询数据库得到。 <BR>二、表头所对应的列的key及名称,也是json串格式 <BR>三、表所对应的id <BR>注:此处只是适合表头只有一行,且事先写好的情况。您可以根据需要改一下,逻辑思路就是这样,欢迎批评指正。 <BR>*/ <BR>function splitPage(page,pageSize){ <BR>var ptable = document.getElementById("page_table"); <BR>var num = ptable.rows.length;//table.rows返回表格中包含的所有行,此处假设表由表头1行和表体N行组成 <BR>//alert(num); <BR>//清除tbody <BR>for(var i=num-1;i>0;i--){ <BR>ptable.deleteRow(i); <BR>} <BR>var totalNums = tableData.length;//总行数 <BR>var totalPage = Math.ceil(totalNums/pageSize);//总页数 <BR>var begin = (page-1)*pageSize;//页起始位置(包括) <BR>var end = page*pageSize;//页结束位置(不包括) <BR>end = end>totalNums?totalNums:end; <BR>//向tbody中写入数据 <BR>var n = 1;//tbody的起始行 <BR>for(var i=begin;i<end;i++){ <BR>var row = ptable.insertRow(n++); <BR>var rowData = tableData[i]; <BR>for(var j=0;j<columns.length;j++){ <BR>var col = columns[j].cid; <BR>var cell = row.insertCell(j); <BR>var cellData = rowData[col]; <BR>cell.innerHTML = cellData; <BR>} <BR>} <BR>//生成分页工具条 <BR>var pageBar = "第"+page+"页/共"+totalPage+"页"+" "; <BR>if(page>1){ <BR>pageBar += "<a href=\"javascript:splitPage("+1+","+pageSize+");\">首页 "; <BR>}else{ <BR>pageBar += "首页 "; <BR>} <BR>if(page>1){ <BR>pageBar += "<a href=\"javascript:splitPage("+(page-1)+","+pageSize+");\">上一页 "; <BR>}else{ <BR>pageBar += "上一页 "; <BR>} <BR>if(page<totalPage){ <BR>pageBar += "<a href=\"javascript:splitPage("+(page+1)+","+pageSize+");\">下一页 "; <BR>}else{ <BR>pageBar += "下一页 "; <BR>} <BR>if(page<totalPage){ <BR>pageBar += "<a href=\"javascript:splitPage("+(totalPage)+","+pageSize+");\">尾页 "; <BR>}else{ <BR>pageBar += "尾页 "; <BR>} <BR>document.getElementById("page_bar").innerHTML = pageBar; <BR>} <BR> h1 h2 h3 111 222 333