您好,欢迎访问一九零五行业门户网

Jquery+JSon+php 实现代码无刷新分页

js代码
var displaycount;
var getdataurl;
var booktableid;
var currentindex;
var pagecount;
var linkclass;
var fields;
function initpagebar(dc, gdu, btid,pc,lc) {
displaycount = dc;
getdataurl = gdu;
booktableid = btid;
currentindex = 1;
pagecount = pc;
linkclass = .+lc;
$(linkclass).click(getpage);
}
function getpagebyid(id) {
$(#ci).val(id);
var surl = getdataurl+?pageindex= + id;
$.ajax({
url: surl,
type: get,
datatype: json,
timeout: 1000,
success: showresult
}
);
}
function getpage() {
getpagebyid($(this).get(0).id);
}
function showresult(result) {
for (i = 1; i var id = # + booktableid + tr:nth-child( + i + );
obj = result.data[i - 1];
for (var key in obj) {
ctl = $(id).find(. + key);
if (ctl.length > 0) {
ctl.get(0).innerhtml = obj[key];
}
}
}
$(linkclass).each(function(index) {
var i, b, e;
if (result.currentpageindex b = 1;
e = (displaycount + 1) * 2;
i = index - 2 + 1;
}
else if (result.currentpageindex > pagecount - displaycount) {
b = pagecount - displaycount * 2;
e = pagecount;
i = pagecount - displaycount * 2 + index - 2;
}
else {
i = result.currentpageindex - displaycount + index - 2;
b = result.currentpageindex - displaycount - 1;
e = result.currentpageindex + displaycount + 1;
}
if ($(this).get(0).id == $(this).text()) {
$(this).text(i);
}
else if (index == 1) {
if (b $(this).get(0).id = 1;
}
else {
$(this).get(0).id = b - 1;
}
}
else if (index == displaycount * 2 + 3) {
$(this).get(0).id = e;
}
$(this).attr(href, #);
if ((i >= b) && (i $(this).get(0).id = i;
}
if ($(this).text == result.currentpageindex) {
$(this).removeattr(href);
}
});
currentindex = result.currentpageindex;
}
html代码
书名
作者
类别
删除
详细
ajax 返回数据
{data:[{title:c#.net程序设计——国外计算机科学经典教材,categoryname:.net,author:布拉德利(bradley,j.c.),米尔斯波(millspaugh,a.c.) 著, 天宏工作室 译,id:5392},{title:c#2.0〔宝典)(附盘),categoryname:c c++ vc vc++,author:张立 编著,id:5027},{title:c#2.0完全自学手册(附cd),categoryname:c c++ vc vc++,author:张立 等编著,id:5081},{title:c#2005数据库教程编程经典教程,categoryname:c c++ vc vc++,author:(美)沃顿(karli watton) 著,陈秋萍 译,id:4983},{title:c#程序设计教程——计算机基础课程系列教材,categoryname:c c++ vc vc++,author:郑阿奇,梁敬东 主编,id:5127},{title:c#程序员参考手册,categoryname:c c++ vc vc++,author:grant palmer 著,康博 译,id:5132},{title:c#和.net核心技术——开发人员专业技术丛书,categoryname:c c++ vc vc++,author:(美)佩里(perry,s.c.) 著,肖斌 等译,id:5104},{title:c#基础与实例教程(附cd-rom光盘一张),categoryname:c c++ vc vc++,author:郝春强 编著,id:5071},{title:c#软件项目开发全程剖析,categoryname:c c++ vc vc++,author:(德)侯姆,(德)克*,(德)斯普达 著,薛兴涛,袁勤勇 译,id:5034},{title:c#设计模式——开发大师系列,categoryname:c c++ vc vc++,author:(美)麦斯科 著,颜炯 译,id:4954}],currentpageindex:15,pagecount:1074}
using system;
using system.collections.generic;
using system.componentmodel;
using system.linq;
using system.text;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;
using system.reflection;
using system.io;
[assembly: webresource(pagebarjs.js, application/x-javascript教程)]
namespace hawkon.control {
[defaultproperty(text)]
[toolboxdata({0}:pagebar>)]
public class pagebar : webcontrol {
[bindable(true)]
[category(data)]
[defaultvalue(1)]
[localizable(true)]
public int pageindex {
get {
return pageindex;
}
set {
pageindex = value;
}
}
private int pageindex;
[bindable(true)]
[category(data)]
[defaultvalue(1)]
[localizable(true)]
public int pagecount {
get {
return pagecount;
}
set {
pagecount = value;
}
}
private int pagecount;
[bindable(true)]
[category(data)]
[defaultvalue(5)]
[localizable(true)]
public int displaycount {
get {
return displaycount;
}
set {
displaycount = value;
}
}
private int displaycount;
protected override void rendercontents(htmltextwriter output) {
string html = ;
html += createa(1, int b = 0, e = 0;
if (pageindex b = 1;
e = displaycount * 2 + 1;
}
else if (pageindex > pagecount - displaycount) {
b = pagecount - displaycount * 2;
e = pagecount;
}
else {
b = pageindex - displaycount;
e = pageindex + displaycount;
}
if (b html += createa(1, );
}
else
html += createa(b - 1, );
for (int i = b; i html += createa(i, i.tostring());
}
html += createa(e + 1, );
html += createa(pagecount, >>);
// html += string.format(,
// this.page.clientscript.getwebresourceurl(typeof(pagebar), jscript1.js));
output.write(html);
}
private string createa(int pageindex, string text) {
if (pageindex == this.pageindex) {
return string.format({1} , pageindex, text);
}
return string.format({1} , pageindex, text);
}
protected override void onprerender(eventargs e) {
base.onprerender(e);
string resourcename = pagebarjs.js;
string url = this.page.clientscript.getwebresourceurl(this.gettype(), pagebarjs.js);
string script = ;
this.page.clientscript.registerclientscriptblock(this.gettype(), resourcename, script, false);
script = @; this.page.clientscript.registerclientscriptblock(this.gettype(), ready, script);
}
protected override void render(htmltextwriter writer) {
base.render(writer);
}
}
}
其它类似信息

推荐信息