怎样分页处理页面 帮忙写下代码谢谢啊
例如:问题
问题
问题
问题一定行数分页
1 2 3 的页面
例如:问题
问题
问题
问题一定行数分页
1 2 3 的页面
解决方案 »
- 怎样把word,ppt,excel文件放在浏览器中展示
- firebug 动态脚本
- 页面无刷新 获取当前时间
- c++语言中的结构如何JS表示?
- onMouseOver , onMouseOut 放在一个包含很多td的tr里时如何防止多次触发
- 用JAVESCRIPT修改控件大小,为什么不执行?加上alert("df")才执行
- 我在父模态窗口里再打开了子模态窗口,但怎么我关闭子窗口会顺便把父窗口也关闭了的?
- 那个JAVASCRIPT日历程序,怎么使它隐藏,在单击网页任一处时?
- scripts问题,我觉得这个问题一流难,能解决的请帮忙,有没可能先?
- 问一下各位要学习java要掌握哪些技术,我是初学者!
- 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();}