Jquery分页

Jquery分页:


Page.jsp:
<%@ page contentType="text/html; charset=UTF-8"%>

<table tabindex="11" class="im_tb data_list" cellspacing="0" rules="all" border="0" id="page" style="border-width:0px;width:100%;border-collapse:collapse;">
<tr class="tr_list">
<input type="hidden" id="pageno" name="pageno" value=""/>
  <td  colspan="100" style="text-align:right;">&nbsp;
    第<span id="curpage">1</span>页/共<span id="pagecount">1</span>页&nbsp;&nbsp;
    共<span id="recordcount">0</span>条记录&nbsp;&nbsp;每页
    <select name="pagesize" id="pagesize" onchange="book()">
       <option >5</option>
      <option >10</option>
      <option >20</option>
      <option >30</option>
      <option>40</option>
      <option>50</option>
      <option>70</option>
    </select>
    行 <span ><a href="#" id="first" style="font-family:Webdings!important;" disabled> 9 </a></span>
    <a href="#" id="pre" style="font-family:Webdings!important;" disabled> 7 </a>
    <input type="text" id="gopage" name="gopage" style="width:40px; background-color:#F5F5F5;" border="0" onKeyUp="this.value=this.value.replace(/\D/g,'')"   onafterpaste="this.value=this.value.replace(/\D/g,'')"/>
    <input type="button" name="button" id="go" value="Go" class="btn_go"/>
    <span><a href="#" id="next" style="font-family:Webdings!important;" disabled> 8 </a></span>
    <a href="#" id="last" style="font-family:Webdings!important;" disabled> :</a></td>
</tr>
</table>

<script language="javascript" type="text/javascript">

$("#go").bind("click",function(){
var pagecount=$("#pagecount").html();
pagecount=parseInt(pagecount);
if($("#gopage").val()==0)
{
$("#gopage").val(1);
}
if($("#gopage").val()>pagecount)
{
$("#gopage").val(pagecount);
}
$("#pageno").val($("#gopage").val());
book();
})

$("#first").bind("click",function(){
$("#pageno").val("1");
book();
})
$("#pre").bind("click",function(){
var pageno=$("#pageno").val();
pageno=parseInt(pageno);
if(pageno>1)
{
$("#pageno").val(pageno-1);
book();
}
})

$("#next").bind("click",function(){
var pageno=$("#pageno").val();
var pagecount=$("#pagecount").html();
pageno=parseInt(pageno);
pagecount=parseInt(pagecount);
if(pageno<pagecount)
{
$("#pageno").val(parseInt(pageno)+1);
book();
}

})
$("#last").bind("click",function(){
var pagecount=$("#pagecount").html();
$("#pageno").val(pagecount);
book();
})


/**
pageno 页码
pagesize 每页数
recordcount 记录总数
pagecount  总页数
*/
function setPageData(pageno,pagesize,recordcount,pagecount)
{
 
pageno=parseInt(pageno)==0?1:pageno;
pagesize=parseInt(pagesize);
recordcount=parseInt(recordcount);
pagecount=parseInt(pagecount)==0?1:pagecount;

alert(pageno+":"+pagesize+":"+recordcount+":"+pagecount);
if(pageno>pagecount)
{
pageno=pagecount;
}

$("#pageno").val(pageno+"");
$("#curpage").html(pageno+"");
$("#pagesize").val(pagesize+"");
$("#recordcount").html(recordcount+"");
$("#pagecount").html(pagecount+"");


$("#first").attr("disabled",pageno<=1);
$("#pre").attr("disabled",pageno<=1);
$("#next").attr("disabled",pageno>=pagecount);
$("#last").attr("disabled",pageno>=pagecount);
}
</script>



Jquery.js:
function book()
{
 
  var StartRow= $("#pageno").val();
  var pagesize=$("#pagesize").val();

   if (StartRow == null || StartRow == "") {
StartRow = "1";
}
if (pagesize == null || pagesize == "") {
pagesize = "5";
}

var row = (parseInt(StartRow) - 1) * parseInt(pagesize);
 
  $.ajax({
   type:'post',
   url:'bookShop.do',
   cache:false,
   async:true,
   data:{parameter:'bookInfo',startRow:row,pageSize:pagesize},
    success:function(transport)
    {
      var de=transport.documentElement;
      var pageRow=de.getElementsByTagName("pageRow")[0].text;
      var pageSize=de.getElementsByTagName("pageSize")[0].text;
      var rowCount=de.getElementsByTagName("rowCount")[0].text;
      var pageCount=de.getElementsByTagName("pageCount")[0].text;
    
       var nodelist = de.getElementsByTagName("bklist");
       var htmlstr = "";
   for (var i = 0; i < nodelist.length; i++) {
        var id=nodelist[i].getElementsByTagName("id")[0].text;
var author = nodelist[i].getElementsByTagName("author")[0].text;
var bookname = nodelist[i].getElementsByTagName("bookname")[0].text;
var bookid = nodelist[i].getElementsByTagName("bookid")[0].text;
var bookprice = nodelist[i].getElementsByTagName("price")[0].text;

htmlstr += "<tr>"
+"<td>"
+id
+"</td>"
+"<td id='bookid'>"
    + bookid
    + "</td>"
    + "<td>"
    + "<a href=#>"
    + bookname
    + "</a>"
    + "</td>"
    + "<td>"
    + author
    + "</td>"
    + "<td id='price'>"
    + bookprice + "</td>"
    + "<td>"
    + "<a href=bookShop.do?parameter=getBookListCar&bookid=" + bookid + ">"
    + "shoping";
htmlstr += "</a><input type='button' value='\u7f16\u8f91' id='edit' onclick='edit(this)'></td>";
htmlstr += "</tr>";
}
     $("#memberList").html(htmlstr);
     setPageParam(pageRow,pageSize,rowCount,pageCount);
    }
  });
    
}
function setPageParam(pageRow,pageSize,rowCount,pageCount)
{
  
    var pageNo;                   //第几页
if (pageRow % pageSize == 0) {
pageNo = pageRow / pageSize + 1;
} else {
pageNo = pageRow / pageSize;
}

setPageData(pageNo, pageSize, rowCount, pageCount);
}


Action:
public ActionForward bookInfo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

int startRow=Integer.parseInt(request.getParameter("startRow"));
int pageSize=Integer.parseInt(request.getParameter("pageSize"));

Document doc = DocumentHelper.createDocument();
Element rsp = doc.addElement("rsp");
Element el = null;
Element booklist=null;

        DataPage<Bookshoping> page=new DataPage<Bookshoping>(startRow,pageSize);
List<Bookshoping> book = bookShopListBiz.getBookShopList(page,startRow,pageSize);

    el = rsp.addElement("page");
    el.addElement("pageRow").setText(String.valueOf(page.getPageNum()));       //从第几条开始显示 
el.addElement("pageSize").setText(String.valueOf(page.getPageSize()));      //每页显示几条
el.addElement("rowCount").setText(String.valueOf(page.getTotalCount()));    //共多少条数据
el.addElement("pageCount").setText(String.valueOf(page.getPageCount()));    //分几页

for(Bookshoping bk:book)
{
booklist=rsp.addElement("bklist");
booklist.addElement("id").setText(String.valueOf(bk.getId()));
booklist.addElement("bookid").setText(String.valueOf(bk.getBookid()));
booklist.addElement("bookname").setText(bk.getBookname());
booklist.addElement("author").setText(bk.getAuthor());
booklist.addElement("price").setText(String.valueOf(bk.getPrice()));
}
writerXML(response, doc);
return null;

}


entity:
package cn.com.zte.Biz.Page;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("serial")
public class DataPage<T> implements Serializable{

//当前页数
private int pageNum;

//每页数量
private int pageSize;

//总数
private int totalCount;

private List<T> data;

public DataPage(int pageNum,int pageSize)
{
this.pageNum=pageNum;
this.pageSize=pageSize; 
this.data=new ArrayList<T>();
}

/**
* 获取开始的行数
* @return
*/
public int getStartRow()
{
return this.pageNum;
}


/**
* 获取总页数
* @return
*/
public int getPageCount()
{
if(this.pageSize<1 || this.totalCount<1)
{
return 0;
}
else
{
if(totalCount%pageSize==0)
{
return totalCount/pageSize;
}else
{
return totalCount/pageSize+1;
}
}
}
public int getPageNum() {
return pageNum;
}

public void setPageNum(int pageNum) {
this.pageNum = pageNum;
}

public int getPageSize() {
return pageSize;
}

public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}

public int getTotalCount() {
return totalCount;
}

public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}

public List<T> getData() {
if(data==null)
{
data=new ArrayList<T>();
}
return data;
}

public void setData(List<T> data) {
this.data = data;
}

}




你可能感兴趣的:(html,jquery,Ajax,jsp,Go)