Jquery:ajax實現翻頁無重新整理功能代碼_jquery

來源:互聯網
上載者:User
不多說,直接貼代碼:
下面是js部分:
複製代碼 代碼如下:

var pageSize = "10";//每頁行數
var currentPage = "1";//當前頁
var totalPage = "0";//總頁數
var rowCount = "0";//總條數
var params="";//參數
var url="activity_list.action";//action
$(document).ready(function(){//jquery代碼隨著document載入完畢而載入
//分頁查詢
function queryForPages(){
$.ajax({
url:url,
type:'post',
dataType:'json',
data:"qo.currentPage="+currentPage+"&qo.pageSize="+pageSize+params,
success:function callbackFun(data){
//解析json
var info = eval("("+data+")");
//清空資料
clearDate();
fillTable(info);
}
});
}
//填充資料
function fillTable(info){
if(info.length>1){
totalPage = info[info.length-1].totalPage;
var tbody_content="";//不初始化字串"",會預設"undefined"
for(var i=0 ; i<info.length-1;i++){
tbody_content +="<tr>"
+"<td data-title='序號' >"+(i+1+(currentPage-1)*pageSize)+"</td>"
+"<td data-title='標題'>"+info[i].title.substr(0,20)+"</td>"
+"<td data-title='地點'>"+info[i].address.substr(0,6)+"</td>"
+"<td data-title='已報名'>"+info[i].quota_sign+"人</td>"
+"<td data-title='類別'>"+info[i].type+"</td>"
+"<td data-title='操作'><a href='<%=request.getContextPath()%>/activity_edit.action?id="+info[i].id+"'>編輯</a></td>"
+"</tr>"
$("#t_body").html(tbody_content);
}
}else{
$("#t_head").html("");
$("#t_body").html("<div style='height: 200px;width: 700px;padding-top: 100px;' align='center'>"+info.msg+"</div>");
}
}

//清空資料
function clearDate(){
$("#t_body").html("");
}

//搜尋活動
$("#searchActivity").click(function(){ queryForPages(); });
//首頁
$("#firstPage").click(function(){
currentPage="1";
queryForPages();
});
//上一頁
$("#previous").click(function(){
if(currentPage>1){
currentPage-- ;
}
queryForPages();
});
//下一頁
$("#next").click(function(){
if(currentPage<totalPage){
currentPage++ ;
}
queryForPages();
});
//尾頁
$("#last").click(function(){
currentPage = totalPage;
queryForPages();
});

});

下面是html代碼部分:
複製代碼 代碼如下:

<table class="table style-5">
<thead id="t_head">
<tr>
<th>序號</th>
<th>標題</th>
<th>地點</th>
<th>已報名</th>
<th>類別</th>
<th>操作</th>
</tr>
</thead>
<tbody id="t_body">
<!-- ajax填充列表 -->
</tbody>
</table>
<button id="firstPage">首頁</button>
<button id="previous">上一頁</button>
<button id="next">下一頁</button>
<button id="last">尾頁</button>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.