較好的分頁方法

來源:互聯網
上載者:User

<!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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.