现在的位置: 首页 > 综合 > 正文

较好的分页方法

2013年01月19日 ⁄ 综合 ⁄ 共 4494字 ⁄ 字号 评论关闭

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<style>
*{font-size:13px}
</style>
</HEAD>

<BODY>
<script>
var Request =
{
QueryString: new ThunderBirdRequestQueryString(),
Cookies: new ThunderBirdRequestCookies()
}
function ThunderBirdRequestQueryString()
{
this.Current = document.location.search;
this.count = 0;
this.Item = new Array();
this.item = function (strKey)
{
if ( typeof(this.Item[strKey]) != "undefined" )
{
return this.Item[strKey];
}
else
{
return "";
}
}
ThunderBirdRequestOnInit(/([^?&][a-z/d]*)=([^#&]*)/gim, this.Current, this.count, this.Item);
}
function ThunderBirdRequestCookies()
{
this.Current = document.cookie;
this.count = 0;
this.Item = new Array();
this.item = function (strKey)
{
if ( typeof(this.Item[strKey]) != "undefined" )
{
return this.Item[strKey];
}
else
{
return "";
}
}
ThunderBirdRequestOnInit(/([^?&][a-z/d]*)=([^#&;]*)/gim, this.Current, this.count, this.Item);
}
function ThunderBirdRequestOnInit(RegExpRule, Current, count, Item)
{
if ( Current != "" )
{
while ( RegExpRule.exec(Current) != null )
{
Item[RegExp.$1] = RegExp.$2;
Item[count] = RegExp.$2;
count += 1;
}
}
}

var conn=new ActiveXObject("adodb.connection")
connstr="provider=Microsoft.jet.oledb.4.0;data source=test.mdb"
try
{
conn.open(connstr)
}
catch (e)
{
var cat=new ActiveXObject("adox.catalog")
catstr="provider=Microsoft.jet.oledb.4.0;data source=test.mdb"
cat.create(catstr)
conn.open(connstr)
conn.execute("create table test(id int identity(1,1),username varchar(15),userpwd varchar(15))")
for(i=0;i<2000;i++)
conn.execute("insert into test(username,userpwd)values('admin"+i+"','pwd"+i+"')")
}
var rs=new ActiveXObject("adodb.recordset")
sql="select * from test"
rs.open(sql,conn,1)
if (rs.eof||rs.bof)
{
document.write("数据为空")
document.close()
}
PageNo=Request.QueryString.item("page")
MPageSize=10
rscount=rs.recordcount
if(typeof(PageNo)=="undefined"||Math.floor(PageNo)<=0)PageNo=1

if((rscount%MPageSize)==0){
PageCount=rscount/MPageSize
}else
{
PageCount= rscount/MPageSize+1
}

if(PageCount<=0)PageCount=PageNo
if(Math.floor(PageNo)>PageCount&&PageCount>0)PageNo=PageCount
rs.absoluteposition=rs.absoluteposition+((Math.abs(PageNo)-1)*MPageSize)
TopicList=new VBArray(rs.getrows(MPageSize))
rs=null;
conn=null;
for(i=0;i<TopicList.ubound(2);i++)
{
document.write(TopicList.getItem(1,i)+"=============="+TopicList.getItem(2,i)+"<br>")
}

document.write(PageList(MPageSize,rscount,PageNo))

function PageList(iPageValue,iRetCount,iCurrentPage,FieldName,FieldValue)
{
var Url
var PageCount //页总数
var PageRoot //页列表头
var PageFoot //页列表尾
var OutStr
var i //输出字符串
var StepNum=3 //页码步长

if((iRetCount%iPageValue)==0){
PageCount=iRetCount/iPageValue
}
else{
PageCount=(iRetCount/iPageValue)+1
}
if(iCurrentPage-StepNum<=1){
PageRoot=1}
else{
PageRoot=iCurrentPage-StepNum
}
if(iCurrentPage+StepNum>=PageCount){
PageFoot=PageCount}
else{
PageFoot=iCurrentPage+StepNum
}

OutStr="分页:"+iCurrentPage+"/"+PageCount+"页 "

if(PageRoot==1){
if(iCurrentPage==1){
OutStr+="<font color=888888 face=webdings>9</font></a>"
OutStr+="<font color=888888 face=webdings>7</font></a> "
}else{
OutStr+="<a href='?page=1"

OutStr+="' title='首页'><font face=webdings>9</font></a>"
OutStr+="<a href='?page="+(iCurrentPage-1)
OutStr+="' title=上页><font face=webdings>7</font></a>"
}
}else{
OutStr+="<a href='?page=1"

OutStr+="' title='首页'><font face=webdings>9</font></a>"
OutStr+="<a href='?page="+(iCurrentPage-1)
OutStr+="' title='上页'><font face=webdings>7</font></a>..."
}

for(i=PageRoot;i<PageFoot;i++){
if(i==parseInt(iCurrentPage)){
OutStr+="<font color='red'>["+String(i)+"]</font> "
}
else{
OutStr+="<a href='?page="+String(i)

OutStr+="'>["+String(i)+"]</a> "
}
if(i==PageCount)break;
}

if(PageFoot==PageCount){
if(parseInt(iCurrentPage)==parseInt(PageCount)){
OutStr+="<font color=888888 face=webdings>8</font></a>"
OutStr+="<font color=888888 face=webdings>:</font></a>"
}else{
OutStr+="<a href='?page="+(iCurrentPage+1)

OutStr+="' title='下页'><font face=webdings>8</font></a>"
OutStr+="<a href='?page="+PageCount

OutStr+="' title='尾页'><font face=webdings>:</font></a>"
}
}else{
OutStr+="... <a href='?page="+(iCurrentPage+1)

OutStr+="' title='下页'><font face=webdings>8</font></a>"
OutStr+="<a href='?page="+PageCount

OutStr+="' title='尾页'><font face=webdings>:</font></a>"
}

OutStr+="  <INPUT TYPE=text class=iptA size=3 value="+iCurrentPage+" onmouseover='this.focus();this.select()' NAME=PGNumber> <INPUT TYPE=button id=button1 name=button1 class=btnA value=GO onclick=/"if(document.all.PGNumber.value>0&& document.all.PGNumber.value<="+iRetCount+"){window.location='?page='+document.all.PGNumber.value}/">"
return OutStr
}
</script>
</BODY>
</HTML>

抱歉!评论已关闭.