asp分頁的基於對象的解決

來源:互聯網
上載者:User
對象|分頁|解決 在論壇上有不少的關於asp分頁的文章,基本思想是一致的,我把這些網友的思路深化了一下,用javaScript套上了一層基於對象的外衣,這樣調用起來就不顯得亂了,其它的話就不多說了,詳見程式中的注釋。

下邊是來源程式:
<script language=javascript runat=server>
function trim(str)//去掉字串的首尾空格
{ var tmpStr=new String(str)
return tmpStr.replace(/(^\s*)|(\s*$)/g, "");
}
</script>


<SCRIPT LANGUAGE=javascript RUNAT=Server>
// ************************************************************************
// Script Compont Object Model
// Design for Active Server Pages
//
// Copyright 2003 Version 1.0
// Made by yinShuGuang
// All Rights Reserved.
// ************************************************************************

function JPageNavbar(){
_LB__Prototype();
}
function _LB__Prototype()
{

// public members
JPageNavbar.prototype.PageSize="0"
JPageNavbar.prototype.RecordCount="0" //總記錄數
JPageNavbar.prototype.PageCount="1" //總頁數
JPageNavbar.prototype.CurrentPage="1"

JPageNavbar.prototype.PnWidth="100%"
JPageNavbar.prototype.PnAlign="right"
JPageNavbar.prototype.PlWidth="100%" //表格寬度
JPageNavbar.prototype.PlAlign="right" // 表格的對齊

// private members

//public methods
JPageNavbar.prototype.getCurrentPage=_getCurrentPage
JPageNavbar.prototype.pnDisplay = _PN_show;
JPageNavbar.prototype.plDisplay = _PL_show;

//private methods


//scope implementation in _LB__Prototype function

function _getCurrentPage(){
var pageNo=new String() //當前顯示的是第幾頁
//取得當前頁
pageNo = Request.QueryString ("PageNo")
pageNo=fTrim(pageNo)
//如果沒有選擇第幾頁,則預設顯示第一頁;
if (pageNo=="") {
pageNo = 1
}
this.CurrentPage=pageNo
return pageNo
}
function _PL_show(){

var strBuilder=new String()
strBuilder=""
var p=(this.CurrentPage-(this.CurrentPage%10))/10 //計算分頁顯示的頁數
//首組為第0族

strBuilder+="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" "
strBuilder+=" width=\""+this.PlWidth+"\" align=\""+this.PlAlign+"\">"

strBuilder+=" <tr> "
strBuilder+=" <td valign=\"middle\" align=\"right\">分頁:"

if (this.CurrentPage==1){
strBuilder+="<font face=\"webdings\" color=\"#ff0000\">9</font> "
}
else{
strBuilder+="<a href=\"?PageNo=1\" title=\"首頁\"><font face=\"webdings\">9</font></a>

"
}
//上十頁
if (p*10>0){
strBuilder+="<a href=\"?PageNo="+(p*10)+"\" title=上十頁><font

face=\"webdings\">7</font></a> "
}
strBuilder+="<b>"
//分頁列表
for(var i=p*10+1;i<=p*10+10;i++){
if (i==this.CurrentPage){
strBuilder+="<font color=\"#000000\">"+i+"</font> "
}
else{
strBuilder+="<a href=?PageNo="+i+" title=\"轉到: 第"+i+"頁\">"+i+"</a> "
}
if (i>=this.PageCount) break;
}
strBuilder+= "</b>"
//顯示下十頁
if (i<this.PageCount){
strBuilder+="<a href=\"?PageNo="+i+"\" title=\"下十頁\"><font

face=\"webdings\">8</font></a> "
}
//顯示尾頁
if (this.CurrentPage==this.PageCount){
strBuilder+= "<font face=\"webdings\" color=\"#000000\">:</font> "
}
else{
strBuilder+= "<a href=?PageNo="+this.PageCount+" title=\"尾頁\"><font

face=\"webdings\">:</font></a> "
}
strBuilder+= "</td></tr></table>"
Response.Write(strBuilder)
}
function _PN_show(){
var strBuilder=new String()



聯繫我們

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