求助分页处理代码? 怎样分页处理页面 帮忙写下代码谢谢啊例如:问题 问题 问题 问题一定行数分页1 2 3 的页面 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 跟其他编程一样啊设置好pagesize,pageindex,计算好recordcount,pagecount等然后动态构造HTML DOM function ShowPage(index, pagecount) { this.Index = index;//当前页码 this.PageCount = pagecount;//总页码 this.ItemCount = 5;//一栏显示多少页 this.Func = "doAjax";//提取数据的方法名,自定义 this.ShowDiv = "_pager";//显示分页的html标签id this.IsShowGo = true;//是否显示跳页功能 this.MaxLength = 3;//跳页功能的输入框,最多输入几个数字 this.Type = "Simple"; //Complex}ShowPage.prototype._Id = function(val) { return document.getElementById(val);}ShowPage.prototype._GetFunction = function(variable, method, param) { return function() { variable[method](param); }}ShowPage.prototype._Go = function(p) { var obj = this._Id('_goto'); if (obj.value) { var val = parseInt(obj.value); if (val == 0 || isNaN(val)) return; else if (val > p) this._DoPage(p); else this._DoPage(val); }}ShowPage.prototype._DoPage = function(p) { try { eval(this.Func + "(" + p + ")"); } catch (e) { alert('找不到' + this.Func + '()这个方法'); return; } this.Index = parseInt(p); this.Init();}ShowPage.prototype._Load = function() { if (this.Index < 1 || this.PageCount < 2) { this._Id(this.ShowDiv).innerHTML = ""; return; } var arr = new Array; var i = 0; if (this.Type == "Simple") { arr[i++] = '<ol style="padding:0px; margin:0px; list-style:none;">'; arr[i++] = '<li style="display:inline; padding-right:15px;">'; if (this.Index == 1) { arr[i++] = '<a href="#0" style="line-height:19px;display:inline-block;color:#aaaaaa;cursor:default;">首页</a> '; arr[i++] = '<a href="#0" style="line-height:19px;display:inline-block;color:#aaaaaa;cursor:default;">上一页</a> '; } else { arr[i++] = '<a href="#1" style="line-height:19px;display:inline-block;color:#0066FF;">首页</a> '; arr[i++] = '<a href="#' + (this.Index - 1) + '" style="line-height:19px;display:inline-block;color:#0066FF;">上一页</a> '; } if (this.Index == this.PageCount) { arr[i++] = '<a href="#0" style="line-height:19px;display:inline-block;color:#aaaaaa;cursor:default;">下一页</a> '; arr[i++] = '<a href="#0" style="line-height:19px;display:inline-block;color:#aaaaaa;cursor:default;">尾页</a>'; } else { arr[i++] = '<a href="#' + (this.Index + 1) + '" style="line-height:19px;display:inline-block;color:#0066FF;">下一页</a> '; arr[i++] = '<a href="#' + this.PageCount + '" style="line-height:19px;display:inline-block;color:#0066FF;">尾页</a>'; } arr[i++] = '</li>'; arr[i++] = '<li style="display:inline;color:#656565;padding-left:15px;">'; arr[i++] = '共' + this.PageCount + '页,当前' + this.Index + '页'; if (this.IsShowGo) { arr[i++] = ', 转到:<input id="_goto" type="text" onpaste="return false" maxlength="' + this.MaxLength + '" style="width:' + (15 + this.MaxLength * 4) + 'px;height:14px;ime-mode:disabled;border:#656565 1px solid;color:#656565;padding-left:2px;" /> 页 ' arr[i++] = '<input type="button" id="_submit" value="GO" style="width:32px; height:18px;cursor:pointer;border:1px solid #aaaaaa;background-color:#cceeff;color:#656565;" />'; } arr[i++] = '</li>'; arr[i++] = '</ol> '; } if (this.Type == "Complex") { var quotient, remainder, base; quotient = Math.floor(this.Index / this.ItemCount); remainder = this.Index % this.ItemCount; base = remainder == 0 ? (quotient - 1) * this.ItemCount + 1 : quotient * this.ItemCount + 1; arr[i++] = '<ol style="padding:0px; margin:0px; list-style:none;">'; arr[i++] = '<li style="display:inline; padding-right:15px;">'; if (this.Index == 1) { arr[i++] = '<a href="#0" title="首页" style="cursor:default;border:1px solid #aaaaaa;height:19px;text-align:center;width:20px;line-height:19px;display:inline-block;color:#aaaaaa;"><<</a> '; } else { arr[i++] = '<a href="#1" title="首页" style="border:1px solid #aaaaaa;height:19px;text-align:center;width:20px;line-height:19px;display:inline-block;color:#656565;"><<</a> '; } if (this.Index < this.ItemCount + 1) { arr[i++] = '<a href="#0" title="前翻" style="cursor:default;border:1px solid #aaaaaa;height:19px;text-align:center;width:20px;line-height:19px;display:inline-block;color:#aaaaaa;"><</a> '; } else { arr[i++] = '<a href="#' + (base - this.ItemCount) + '" title="前翻" style="border:1px solid #aaaaaa;height:19px;text-align:center;width:20px;line-height:19px;display:inline-block;color:#656565;"><</a> '; } for (j = base; j < base + this.ItemCount && j <= this.PageCount; j++) { if (j == this.Index) arr[i++] = '<a href="#0" style="cursor:default;border:1px solid #aaaaaa;background-color:#cceeff;height:19px;text-align:center;font-weight:bold;width:20px;line-height:19px;display:inline-block;color:#656565;">' + j + '</a> '; else arr[i++] = '<a href="#' + j + '" style="border:1px solid #aaaaaa;height:19px;text-align:center;width:20px;line-height:19px;display:inline-block;color:#656565;">' + j + '</a> '; } if ((base + this.ItemCount - 1) < this.PageCount) { arr[i++] = '<a href="#' + (base + this.ItemCount) + '" title="后翻" style="border:1px solid #aaaaaa;height:19px;text-align:center;width:20px;line-height:19px;display:inline-block;color:#656565;">></a> '; } else { arr[i++] = '<a href="#0" title="后翻" style="cursor:default;border:1px solid #aaaaaa;height:19px;text-align:center;width:20px;line-height:19px;display:inline-block;color:#aaaaaa;">></a> '; } if (this.Index == this.PageCount) { arr[i++] = '<a href="#0" title="尾页" style="cursor:default;border:1px solid #aaaaaa;height:19px;text-align:center;width:20px;line-height:19px;display:inline-block;color:#aaaaaa;">>></a>'; } else { arr[i++] = '<a href="#' + this.PageCount + '" title="尾页" style="border:1px solid #aaaaaa;height:19px;text-align:center;width:20px;line-height:19px;display:inline-block;color:#656565;">>></a>'; } arr[i++] = '</li>'; arr[i++] = '<li style="display:inline;color:#656565;padding-left:15px;">'; arr[i++] = '共' + this.PageCount + '页'; if (this.IsShowGo) { arr[i++] = ', 转到:<input id="_goto" type="text" onpaste="return false" maxlength="' + this.MaxLength + '" style="width:' + (15 + this.MaxLength * 4) + 'px;height:14px;ime-mode:disabled;border:#656565 1px solid;color:#656565;padding-left:2px;" /> 页 ' arr[i++] = '<input type="button" id="_submit" value="GO" style="width:32px; height:18px;cursor:pointer;border:1px solid #aaaaaa;background-color:#cceeff;color:#656565;" />'; } arr[i++] = '</li>'; arr[i++] = '</ol> '; } var obj = this._Id(this.ShowDiv); obj.style.margin = "10px 30px 10px 30px;"; obj.style.fontSize = "12px"; obj.style.width = "auto"; obj.style.clear = "both"; obj.style.textAlign = "right"; obj.innerHTML = arr.join('');}ShowPage.prototype._RegisterClick = function() { var obj = this._Id(this.ShowDiv); var aArray = obj.getElementsByTagName('a'); for (var i = 0; i < aArray.length; i++) { var index = aArray[i].href.indexOf('#'); if (index > -1) { var n = aArray[i].href.slice(index + 1); if (n != 0) aArray[i].onclick = this._GetFunction(this, "_DoPage", n); } aArray[i].href = "javascript:void(0);"; } var iArray = obj.getElementsByTagName('input'); for (var i = 0; i < iArray.length; i++) { if (iArray[i].id == '_goto') iArray[i].onkeypress = function(e) { e = e || event; var currKey = e.keyCode || e.which || e.charCode; if (currKey < 58 && currKey > 47) { return true; } return false; } if (iArray[i].id == '_submit') iArray[i].onclick = this._GetFunction(this, "_Go", this.PageCount); }}ShowPage.prototype.Init = function() { this._Load(); this._RegisterClick();} //---------------------demo------------------------///*翻页控件*/<script type="text/javascript" src="js/showPage.js"></script> <script type="text/javascript"> function funPage() { var pp = new ShowPage(1,<%= pcount %>); pp.ItemCount = 5; pp.Func = "myAjax"; pp.ShowDiv = "_test"; pp.Type = "Simple"; //Complex pp.Init(); } function myAjax(p){ document.getElementById('output').innerHTML ="<br/>Please wait a moment …"; //自定义和后台交互取数据,参数p是当前页码 --------------------demo------------------------jQuery.ajax({ url: '<%=Request.FilePath %>', data: {p:p}, cache: false, success: function(res) { document.getElementById('output').innerHTML = res; }, error: function() { alert('error,please refresh.'); window.location.reload(); } });------------------------------------------demo end--------------- } window.onload = funPage;</script><body><div id="output">//------------……//数据,比如一个Repeater</div> <ul id="_test"></ul> </body>----------------------------后台- demo-----------------protected int pcount = 1; //定义变量,记录总页数,在后面的代码要更新该参数if (有p变量){ Response.ClearContent(); GetInfo(p);//获取第p页的数据,并把数据绑定给Repeater System.Text.StringBuilder sb = new System.Text.StringBuilder(); System.IO.StringWriter sw = new System.IO.StringWriter(sb); HtmlTextWriter ht = new HtmlTextWriter(sw); Repeater.RenderControl(ht); Response.Write(sb.ToString()); Response.End();} 求js获取服务器时间(动态更新) lang["abcd"]什么意思 动态图片的问题 如何用JS递归一个目录下所有子目录(文件不用)。 求助,javasript 传递值出现错误 各位大神请教一个js问题 javaBean在TOMCAT中如何放置 各位高手请帮帮我这个可怜的初学者,一个小问题 怎样用JS弹出一个对话框,确认后继续,取消后就停止??? 一个正则式的小问题 Jquery animate可否重写CSS js如何停止当前页面?
设置好pagesize,pageindex,计算好recordcount,pagecount等
然后动态构造HTML DOM
this.Index = index;//当前页码
this.PageCount = pagecount;//总页码
this.ItemCount = 5;//一栏显示多少页
this.Func = "doAjax";//提取数据的方法名,自定义
this.ShowDiv = "_pager";//显示分页的html标签id
this.IsShowGo = true;//是否显示跳页功能
this.MaxLength = 3;//跳页功能的输入框,最多输入几个数字
this.Type = "Simple"; //Complex
}
ShowPage.prototype._Id = function(val) {
return document.getElementById(val);
}
ShowPage.prototype._GetFunction = function(variable, method, param) {
return function() {
variable[method](param);
}
}
ShowPage.prototype._Go = function(p) {
var obj = this._Id('_goto');
if (obj.value) {
var val = parseInt(obj.value);
if (val == 0 || isNaN(val))
return;
else
if (val > p)
this._DoPage(p);
else
this._DoPage(val);
}
}
ShowPage.prototype._DoPage = function(p) {
try {
eval(this.Func + "(" + p + ")");
}
catch (e) {
alert('找不到' + this.Func + '()这个方法');
return;
}
this.Index = parseInt(p);
this.Init();
}
ShowPage.prototype._Load = function() {
if (this.Index < 1 || this.PageCount < 2) {
this._Id(this.ShowDiv).innerHTML = "";
return;
}
var arr = new Array; var i = 0;
if (this.Type == "Simple") {
arr[i++] = '<ol style="padding:0px; margin:0px; list-style:none;">';
arr[i++] = '<li style="display:inline; padding-right:15px;">';
if (this.Index == 1) {
arr[i++] = '<a href="#0" style="line-height:19px;display:inline-block;color:#aaaaaa;cursor:default;">首页</a> ';
arr[i++] = '<a href="#0" style="line-height:19px;display:inline-block;color:#aaaaaa;cursor:default;">上一页</a> ';
}
else {
arr[i++] = '<a href="#1" style="line-height:19px;display:inline-block;color:#0066FF;">首页</a> ';
arr[i++] = '<a href="#' + (this.Index - 1) + '" style="line-height:19px;display:inline-block;color:#0066FF;">上一页</a> ';
}
if (this.Index == this.PageCount) {
arr[i++] = '<a href="#0" style="line-height:19px;display:inline-block;color:#aaaaaa;cursor:default;">下一页</a> ';
arr[i++] = '<a href="#0" style="line-height:19px;display:inline-block;color:#aaaaaa;cursor:default;">尾页</a>';
}
else {
arr[i++] = '<a href="#' + (this.Index + 1) + '" style="line-height:19px;display:inline-block;color:#0066FF;">下一页</a> ';
arr[i++] = '<a href="#' + this.PageCount + '" style="line-height:19px;display:inline-block;color:#0066FF;">尾页</a>';
}
arr[i++] = '</li>';
arr[i++] = '<li style="display:inline;color:#656565;padding-left:15px;">';
arr[i++] = '共' + this.PageCount + '页,当前' + this.Index + '页';
if (this.IsShowGo) {
arr[i++] = ', 转到:<input id="_goto" type="text" onpaste="return false" maxlength="' + this.MaxLength + '" style="width:' + (15 + this.MaxLength * 4) + 'px;height:14px;ime-mode:disabled;border:#656565 1px solid;color:#656565;padding-left:2px;" /> 页 '
arr[i++] = '<input type="button" id="_submit" value="GO" style="width:32px; height:18px;cursor:pointer;border:1px solid #aaaaaa;background-color:#cceeff;color:#656565;" />';
}
arr[i++] = '</li>';
arr[i++] = '</ol> ';
}
if (this.Type == "Complex") {
var quotient, remainder, base;
quotient = Math.floor(this.Index / this.ItemCount);
remainder = this.Index % this.ItemCount;
base = remainder == 0 ? (quotient - 1) * this.ItemCount + 1 : quotient * this.ItemCount + 1;
arr[i++] = '<ol style="padding:0px; margin:0px; list-style:none;">';
arr[i++] = '<li style="display:inline; padding-right:15px;">';
if (this.Index == 1) {
arr[i++] = '<a href="#0" title="首页" style="cursor:default;border:1px solid #aaaaaa;height:19px;text-align:center;width:20px;line-height:19px;display:inline-block;color:#aaaaaa;"><<</a> ';
}
else {
arr[i++] = '<a href="#1" title="首页" style="border:1px solid #aaaaaa;height:19px;text-align:center;width:20px;line-height:19px;display:inline-block;color:#656565;"><<</a> ';
}
if (this.Index < this.ItemCount + 1) {
arr[i++] = '<a href="#0" title="前翻" style="cursor:default;border:1px solid #aaaaaa;height:19px;text-align:center;width:20px;line-height:19px;display:inline-block;color:#aaaaaa;"><</a> ';
}
else {
arr[i++] = '<a href="#' + (base - this.ItemCount) + '" title="前翻" style="border:1px solid #aaaaaa;height:19px;text-align:center;width:20px;line-height:19px;display:inline-block;color:#656565;"><</a> ';
}
for (j = base; j < base + this.ItemCount && j <= this.PageCount; j++) {
if (j == this.Index)
arr[i++] = '<a href="#0" style="cursor:default;border:1px solid #aaaaaa;background-color:#cceeff;height:19px;text-align:center;font-weight:bold;width:20px;line-height:19px;display:inline-block;color:#656565;">' + j + '</a> ';
else
arr[i++] = '<a href="#' + j + '" style="border:1px solid #aaaaaa;height:19px;text-align:center;width:20px;line-height:19px;display:inline-block;color:#656565;">' + j + '</a> ';
}
if ((base + this.ItemCount - 1) < this.PageCount) {
arr[i++] = '<a href="#' + (base + this.ItemCount) + '" title="后翻" style="border:1px solid #aaaaaa;height:19px;text-align:center;width:20px;line-height:19px;display:inline-block;color:#656565;">></a> ';
}
else {
arr[i++] = '<a href="#0" title="后翻" style="cursor:default;border:1px solid #aaaaaa;height:19px;text-align:center;width:20px;line-height:19px;display:inline-block;color:#aaaaaa;">></a> ';
}
if (this.Index == this.PageCount) {
arr[i++] = '<a href="#0" title="尾页" style="cursor:default;border:1px solid #aaaaaa;height:19px;text-align:center;width:20px;line-height:19px;display:inline-block;color:#aaaaaa;">>></a>';
}
else {
arr[i++] = '<a href="#' + this.PageCount + '" title="尾页" style="border:1px solid #aaaaaa;height:19px;text-align:center;width:20px;line-height:19px;display:inline-block;color:#656565;">>></a>';
}
arr[i++] = '</li>';
arr[i++] = '<li style="display:inline;color:#656565;padding-left:15px;">';
arr[i++] = '共' + this.PageCount + '页';
if (this.IsShowGo) {
arr[i++] = ', 转到:<input id="_goto" type="text" onpaste="return false" maxlength="' + this.MaxLength + '" style="width:' + (15 + this.MaxLength * 4) + 'px;height:14px;ime-mode:disabled;border:#656565 1px solid;color:#656565;padding-left:2px;" /> 页 '
arr[i++] = '<input type="button" id="_submit" value="GO" style="width:32px; height:18px;cursor:pointer;border:1px solid #aaaaaa;background-color:#cceeff;color:#656565;" />';
}
arr[i++] = '</li>';
arr[i++] = '</ol> ';
}
var obj = this._Id(this.ShowDiv);
obj.style.margin = "10px 30px 10px 30px;";
obj.style.fontSize = "12px";
obj.style.width = "auto";
obj.style.clear = "both";
obj.style.textAlign = "right";
obj.innerHTML = arr.join('');
}
ShowPage.prototype._RegisterClick = function() {
var obj = this._Id(this.ShowDiv);
var aArray = obj.getElementsByTagName('a');
for (var i = 0; i < aArray.length; i++) {
var index = aArray[i].href.indexOf('#');
if (index > -1) {
var n = aArray[i].href.slice(index + 1);
if (n != 0)
aArray[i].onclick = this._GetFunction(this, "_DoPage", n);
}
aArray[i].href = "javascript:void(0);";
}
var iArray = obj.getElementsByTagName('input');
for (var i = 0; i < iArray.length; i++) {
if (iArray[i].id == '_goto')
iArray[i].onkeypress = function(e) {
e = e || event;
var currKey = e.keyCode || e.which || e.charCode;
if (currKey < 58 && currKey > 47) {
return true;
}
return false;
}
if (iArray[i].id == '_submit')
iArray[i].onclick = this._GetFunction(this, "_Go", this.PageCount);
}
}
ShowPage.prototype.Init = function() {
this._Load();
this._RegisterClick();
}
function funPage() {
var pp = new ShowPage(1,<%= pcount %>);
pp.ItemCount = 5;
pp.Func = "myAjax";
pp.ShowDiv = "_test"; pp.Type = "Simple"; //Complex
pp.Init();
}
function myAjax(p){
document.getElementById('output').innerHTML ="<br/>Please wait a moment …"; //自定义和后台交互取数据,参数p是当前页码 --------------------demo------------------------jQuery.ajax({
url: '<%=Request.FilePath %>',
data: {p:p},
cache: false,
success: function(res) {
document.getElementById('output').innerHTML = res;
},
error: function() {
alert('error,please refresh.');
window.location.reload();
}
});------------------------------------------demo end---------------
}
window.onload = funPage;
</script><body><div id="output">//------------……//数据,比如一个Repeater</div> <ul id="_test"></ul> </body>----------------------------后台- demo-----------------protected int pcount = 1; //定义变量,记录总页数,在后面的代码要更新该参数if (有p变量){ Response.ClearContent();
GetInfo(p);//获取第p页的数据,并把数据绑定给Repeater
System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
HtmlTextWriter ht = new HtmlTextWriter(sw);
Repeater.RenderControl(ht);
Response.Write(sb.ToString());
Response.End();}