asp-----
1
<
%
2
'
author: 伊人芳踪已杳
3
'
date:2006-1-17
4
'
email:jackstudiomaster@gmail.com
5
class Page
6
private
tableStyle,submitImg,currentPage
7
private
pageKey,maxRecordPerPage,showHowMuchPage,recordCount,activeNext,noneNext,activaPreview,nonePreview
8
9
private
sub
class_initialize()
10
tableStyle
=
"
border-TOP:#BDBDBE 1px dashed;background-color:#efefef;
"
11
submitImg
=
"
../images/btn_ok.gif
"
12
pageKey
=
"
page
"
13
recordCount
=
1
14
maxRecordPerPage
=
10
15
showHowMuchPage
=
10
16
activeNext
=
"
../images/next_page_act.gif
"
17
noneNext
=
"
../images/next_page.gif
"
18
activaPreview
=
"
../images/pre_page_simple_act.gif
"
19
nonePreview
=
"
../images/pre_page_simple.gif
"
20
21
currentPage
=
request.queryString(pageKey)
22
if
currentPage
=
""
or
isnull
(currentPage)
=
true
then
currentPage
=
1
23
if
len
(currentPage)
>
6
then
currentPage
=
100000
24
25
end sub
26
27
public
property
let
letTableStyle(str)
28
tableStyle
=
str
29
end property
30
31
public
property
let
letSubmitImg(str)
32
submitImg
=
str
33
end property
34
35
public
property
let
letPageKey(str)
36
pageKey
=
str
37
currentPage
=
request.queryString(pageKey)
38
if
currentPage
=
""
or
isnull
(currentPage)
=
true
then
currentPage
=
1
39
if
len
(currentPage)
>
6
then
currentPage
=
100000
40
end property
41
42
public
property
let
letRecordCount(countValue)
43
if
countValue
=
0
then
44
recordCount
=
1
45
else
46
recordCount
=
countValue
47
end
if
48
end property
49
50
public
property
let
letMaxRecordPerPage(value)
51
maxRecordPerPage
=
value
52
end property
53
54
public
property
let
letShowHowMuchPage(value)
55
showHowMuchPage
=
value
56
end property
57
58
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
59
60
public
property
let
letActiveNext(value)
61
activeNext
=
value
62
end property
63
64
public
property
let
letNoneNext(value)
65
noneNext
=
value
66
end property
67
68
public
property
let
letActivePreview(value)
69
activaPreview
=
value
70
end property
71
72
public
property
let
letNonePreview(value)
73
nonePreview
=
value
74
end property
75
76
77
'
'''''''''''''''''''''''''''''''''''''''''
78
79
80
public
sub
Page()
81
dim
totlePage,beginFor,endFor,pcp,ncp,querystring
'
,currentPage
82
querystring
=
getQueryString(pageKey)
83
if
querystring
<>
""
then
querystring
=
querystring
&
"
&
"
84
85
returnValue
=
"
<table border='0' width=100% style='
"
&
tableStyle
&
"
'>
"
&
vbcrlf
86
returnValue
=
returnValue
&
"
<form id='goPage' name='goPage' method='get' onsubmit='return onCheckPage();'><tr><td align='right' style='FONT-SIZE:10pt;'>
"
&
vbcrlf
87
88
if
(recordCount
mod
maxRecordPerPage)
=
0
then
89
totlePage
=
recordCount
\
maxRecordPerPage
90
else
91
totlePage
=
(recordCount
\
maxRecordPerPage)
+
1
92
end
if
93
94
95
96
97
if
clng
(currentPage)
>=
totlePage
then
98
currentPage
=
totlePage
99
else
100
currentPage
=
currentPage
101
end
if
102
103
if
(currentPage
mod
showHowMuchPage)
=
0
then
104
beginFor
=
currentPage
105
else
106
if
(currentPage
-
(currentPage
mod
showHowMuchPage))
=
0
then
107
beginFor
=
1
108
else
109
beginFor
=
currentPage
-
(currentPage
mod
showHowMuchPage)
110
end
if
111
end
if
112
113
if
(currentPage
mod
totlePage)
=
0
then
114
endFor
=
totlePage
115
else
116
if
(beginFor
+
showHowMuchPage)
>
totlePage
then
117
endFor
=
totlePage
118
else
119
if
beginFor
=
1
then
120
endFor
=
beginFor
+
showHowMuchPage
-
1
121
else
122
endFor
=
beginFor
+
showHowMuchPage
123
end
if
124
end
if
125
end
if
126
127
returnValue
=
returnValue
&
getInput
128
129
130
131
if
currentPage
>
1
then
132
pcp
=
currentPage
-
1
133
returnValue
=
returnValue
&
"
<A href='?
"
&
querystring
&
pageKey
&
"
=
"
&
pcp
&
"
'><img src='
"
&
activaPreview
&
"
' border='0'></A>
"
&
vbcrlf
134
Else
135
returnValue
=
returnValue
&
"
<img src='
"
&
nonePreview
&
"
' style='border:0px none;'>
"
&
vbcrlf
136
end
if
137
138
'
returnValue=returnValue&"</td><td align='right' style='FONT-SIZE:10pt;' nowrap >"
139
140
for
i
=
beginFor
to
endFor
141
if
i
=
clng
(currentPage)
then
142
returnValue
=
returnValue
&
"
<font color='red'>
"
&
i
&
"
</font>
"
&
vbcrlf
143
else
144
returnValue
=
returnValue
&
"
<A href='?
"
&
querystring
&
pageKey
&
"
=
"
&
i
&
"
'>
"
&
i
&
"
</A>
"
&
vbcrlf
145
end
if
146
next
147
148
'
returnValue=returnValue&"</td><td align='right' width='80px'>"
149
150
151
if
clng
(currentPage)
<
totlePage
then
152
ncp
=
currentPage
+
1
153
returnValue
=
returnValue
&
"
<A href='?
"
&
querystring
&
pageKey
&
"
=
"
&
ncp
&
"
'><img src='
"
&
activeNext
&
"
' border='0'></A>
"
&
vbcrlf
154
Else
155
returnValue
=
returnValue
&
"
<img src='
"
&
noneNext
&
"
' border='0'>
"
&
vbcrlf
156
end
If
157
158
159
'
returnValue=returnValue&"</td><td align='right' style='FONT-SIZE:10pt;' width='150px'>"
160
161
returnValue
=
returnValue
&
"
直接到第 <input id='
"
&
pageKey
&
"
' name='
"
&
pageKey
&
"
' size='3' style='height:16px'> 页
"
&
vbcrlf
162
returnValue
=
returnValue
&
"
<img src='
"
&
submitImg
&
"
' align='middle'style='cursor:hand;' onclick='onCheckPage();'>
"
&
vbcrlf
163
164
returnValue
=
returnValue
&
"
</td></tr></form></table>
"
&
vbcrlf
165
returnValue
=
returnValue
&
"
<script language='javascript'>
"
&
vbcrlf
166
returnValue
=
returnValue
&
"
function onCheckPage(){
"
&
vbcrlf
167
returnValue
=
returnValue
&
"
var beginPage =document.goPage.
"
&
pageKey
&
"
.value;
"
&
vbcrlf
168
returnValue
=
returnValue
&
"
if(isNaN(beginPage)){alert('请输入数字!(1到
"
&
totlePage
&
"
)');
"
&
vbcrlf
169
returnValue
=
returnValue
&
"
return false;}
"
&
vbcrlf
170
returnValue
=
returnValue
&
"
if(parseInt(beginPage) < 0 ) { beginPage = 1;}
"
&
vbcrlf
171
returnValue
=
returnValue
&
"
if(beginPage.length > 6 ) { beginPage = 1;}
"
&
vbcrlf
172
returnValue
=
returnValue
&
"
if(beginPage =="""") {beginPage = 1;}
"
&
vbcrlf
173
returnValue
=
returnValue
&
"
if(beginPage >
"
&
totlePage
&
"
){document.goPage.
"
&
pageKey
&
"
.value =
"
&
totlePage
&
"
;}
"
&
vbcrlf
174
returnValue
=
returnValue
&
"
document.goPage.submit();
"
&
vbcrlf
175
returnValue
=
returnValue
&
"
return true;}
"
&
vbcrlf
176
returnValue
=
returnValue
&
"
</script>
"
&
vbcrlf
177
178
response.write(returnValue)
179
180
end sub
181
182
function
getQueryString(pagekey)
183
for
each
e in request.form
184
if
e
<>
pagekey
then
185
getQueryString
=
getQueryString
&
e
&
"
=
"
&
request.Form(e)
&
"
&
"
186
end
if
187
next
188
for
each
e in request.QueryString
189
if
e
<>
pagekey
then
190
getQueryString
=
getQueryString
&
e
&
"
=
"
&
request.QueryString(e)
&
"
&
"
191
end
if
192
next
193
if
getQueryString
<>
""
then
194
getQueryString
=
left
(getQueryString,
len
(getQueryString)
-
1
)
195
else
196
getQueryString
=
""
197
end
if
198
end Function
199
200
201
function
getInput()
202
dim
myQueryString,mySplitQueryString,mySplitQueryStringTwo
203
myQueryString
=
getQueryString(pageKey)
204
if
myQueryString
<>
""
then
205
mySplitQueryString
=
split
(myQueryString,
"
&
"
)
206
for
sQ
=
0
to
ubound
(mySplitQueryString)
207
mySplitQueryStringTwo
=
split
(mySplitQueryString(sQ),
"
=
"
)
208
getInput
=
getInput
&
"
<input type='hidden' id='
"
&
mySplitQueryStringTwo(
0
)
&
"
' name='
"
&
mySplitQueryStringTwo(
0
)
&
"
' value='
"
&
server.HTMLEncode(request(mySplitQueryStringTwo(
0
)))
&
"
'>
"
&
vbcrlf
209
next
210
end
if
211
end function
212
213
214
private
sub
class_terminate()
215
end sub
216
end
class
217
218
'
使用方法
219
220
'
set pM=new Page
221
'
pM.letTableStyle="border:#cccccc 1px solid;background-color:#eeeeee;"
222
'
pM.letPageKey="currentPage"
223
'
pM.letSubmitImg="btn_ok.gif"
224
'
pM.letRecordCount=300
225
'
pM.Page
226
%
>
'调用方法.可以自动获得除指定的参数之外的其他参数(包括Get和Post方式).如果分页参数为page=?,那么无须定义.可直接使用
php-----------
1
<?
2
//
author: 伊人芳踪已杳
3
//date:2006-8-3
4
//email:jackstudiomaster@gmail.com
5
class
Page{
6
var
$tableStyle
=
"
border-TOP:#BDBDBE 1px dashed;background-color:#efefef;
"
;
7
var
$submitImg
=
"
../images/btn_ok.gif
"
;
8
var
$pageKey
=
"
page
"
;
9
var
$maxRecordPerPage
=
10
;
10
var
$showHowMuchPage
=
10
;
11
var
$recordCount
=
1
;
12
var
$activeNext
=
"
../images/next_page_act.gif
"
;
13
var
$noneNext
=
"
../images/next_page.gif
"
;
14
var
$activaPreview
=
"
../images/pre_page_simple_act.gif
"
;
15
var
$nonePreview
=
"
../images/pre_page_simple.gif
"
;
16
var
$currentPage
=
1
;
17
function
letShowHowMuchPage(
$value
){
18
$this
->
showHowMuchPage
=
$value
;
19
}
20
function
letTableStyle(
$str
){
21
$this
->
tableStyle
=
$str
;
22
}
23
function
letSubmitImg(
$str
){
24
$this
->
submitImg
=
$str
;
25
}
26
function
letPageKey(
$str
){
27
$this
->
pageKey
=
$str
;
28
$this
->
currentPage
=
$_GET
[
"
$pageKey
"
] ;
29
}
30
function
letRecordCount(
$countValue
){
31
if
(
$countValue
==
0
){
$this
->
recordCount
=
1
;}
32
else
{
$this
->
recordCount
=
$countValue
;}
33
}
34
function
letMaxRecordPerPage(
$value
){
35
$this
->
maxRecordPerPage
=
$value
;
36
}
37
38
//
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
39
function
letActiveNext(
$value
) {
40
$this
->
activeNext
=
$value
;
41
}
42
43
function
letNoneNext(
$value
) {
44
$this
->
noneNext
=
$value
;
45
}
46
47
function
letActivePreview(
$value
) {
48
$this
->
activaPreview
=
$value
;
49
}
50
51
function
letNonePreview(
$value
) {
52
$this
->
nonePreview
=
$value
;
53
}
54
//
---------------------------------------------
55
//
56
57
function
getQueryString(
$pagekey
){
58
$QueryString
=
""
;
59
while
(
list
(
$key
,
$value
)
=
each
(
$_POST
)) {
60
if
(
$key
!=
$pagekey
){
61
$QueryString
=
$QueryString
.
$e
.
"
=
"
.
$value
.
"
&
"
;
62
}
63
}
64
65
while
(
list
(
$key
,
$value
)
=
each
(
$_GET
)) {
66
if
(
$key
!=
$pagekey
){
67
$QueryString
=
$QueryString
.
$key
.
"
=
"
.
$value
.
"
&
"
;
68
}
69
}
70
71
if
(
$QueryString
!=
""
)
72
$QueryString
=
substr
(
$QueryString
,
strlen
(
$QueryString
)
-
1
);
73
else
74
$QueryString
=
""
;
75
76
return
$QueryString
;
77
}
78
79
function
getInput(){
80
$myQueryString
=
""
;
81
$mySplitQueryString
=
""
;
82
$mySplitQueryStringTwo
=
""
;
83
$Input
=
""
;
84
$myQueryString
=
getQueryString(
$this
->
pageKey);
85
86
if
(
$myQueryString
!=
""
) {
87
$mySplitQueryString
=
split
(
$myQueryString
,
"
&
"
);
88
for
(
$sQ
=
0
;
$sQ
<=
count
(
$mySplitQueryString
);
$sQ
++
){
89
$mySplitQueryStringTwo
=
split
(
$mySplitQueryString
[
$sQ
]
,
"
=
"
);
90
$Input
=
$Input
.
"
<input type='hidden' id='
"
.
$mySplitQueryStringTwo
[
0
]
.
"
' name='
"
.
$mySplitQueryStringTwo
[
0
]
.
"
' value='
"
.
htmlspecialchars
(
$_REQUEST
(
$mySplitQueryStringTwo
[
0
]))
.
"
'>\n
"
;
91
}
92
}
93
return
$Input
;
94
}
95
96
//
--------------------------------------------------
97
function
WritePage(){
98
$totlePage
=
1
;
99
$beginFor
=
""
;
100
$endFor
=
""
;
101
$pcp
=
""
;
102
$ncp
=
""
;
103
$querystring
=
$this
->
getQueryString(
$this
->
pageKey);
104
$returnValue
=
""
;
105
$this
->
currentPage
=
$_REQUEST
[
"
$this->pageKey
"
];
106
107
if
(
$this
->
currentPage
==
""
Or
$this
->
currentPage
==
0
Or
is_null
(
$this
->
currentPage)
==
true
){
$this
->
currentPage
=
1
;}
108
if
(
strlen
(
$this
->
currentPage)
>
6
) {
$this
->
currentPage
=
100000
;}
109
if
(
$querystring
!=
""
) {
$querystring
=
$querystring
.
"
&
"
;}
110
$returnValue
=
"
<table border='0' width=100% style='
"
.
$this
->
tableStyle
.
"
'>\n
"
;
111
$returnValue
=
$returnValue
.
"
<form id='goPage' name='goPage' method='get' onsubmit='return onCheckPage();'><tr><td align='right' style='FONT-SIZE:10pt;'>\n
"
;
112
113
if
((
$this
->
recordCount
%
$this
->
maxRecordPerPage)
==
0
){
114
$totlePage
=
$this
->
recordCount
/
$this
->
maxRecordPerPage;
115
116
}
117
else
{
118
$totlePage
=
floor
(
$this
->
recordCount
/
$this
->
maxRecordPerPage)
+
1
;
119
120
}
121
122
123
124
if
(
$this
->
currentPage
>=
$totlePage
){
125
$this
->
currentPage
=
$totlePage
;
126
}
127
128
if
((
$this
->
currentPage
%
$this
->
showHowMuchPage)
==
0
){
129
$beginFor
=
$this
->
currentPage ;
130
}
131
else
{
132
if
((
$this
->
currentPage
-
(
$this
->
currentPage
%
$this
->
showHowMuchPage))
==
0
){
133
$beginFor
=
1
;
134
}
135
else
{
136
$beginFor
=
$this
->
currentPage
-
(
$this
->
currentPage
%
$this
->
showHowMuchPage) ;
137
}
138
}
139
140
141
if
((
$this
->
currentPage
%
$totlePage
)
==
0
){
142
$endFor
=
$totlePage
;
143
}
144
else
{
145
if
((
$beginFor
+
$this
->
showHowMuchPage)
>
$totlePage
){
146
$endFor
=
$totlePage
;
147
}
148
else
{
149
if
(
$beginFor
==
1
) {
150
$endFor
=
$beginFor
+
$this
->
showHowMuchPage
-
1
;
151
}
152
else
{
153
$endFor
=
$beginFor
+
$this
->
showHowMuchPage ;
154
}
155
}
156
}
157
158
159
160
161
$returnValue
=
$returnValue
.
$getInput
;
162
163
164
165
166
if
(
$this
->
currentPage
>
1
) {
167
$pcp
=
$this
->
currentPage
-
1
;
168
$returnValue
=
$returnValue
.
"
<A href='?
"
.
$querystring
.
$this
->
pageKey
.
"
=
"
.
$pcp
.
"
'><img src='
"
.
$this
->
activaPreview
.
"
' border='0'></A>\n
"
;
169
}
170
Else
{
171
$returnValue
=
$returnValue
.
"
<img src='
"
.
$this
->
nonePreview
.
"
' style='border:0px none;'>\n
"
;
172
}
173
174
for
(
$i
=
$beginFor
;
$i
<=
$endFor
;
$i
++
){
175
if
(
$i
==
$this
->
currentPage) {
176
$returnValue
=
$returnValue
.
"
<font color='red'>
"
.
$i
.
"
</font>\n
"
;
177
}
178
else
{
179
$returnValue
=
$returnValue
.
"
<A href='?
"
.
$querystring
.
$this
->
pageKey
.
"
=
"
.
$i
.
"
'>
"
.
$i
.
"
</A>\n
"
;
180
}
181
}
182
183
184
185
if
(
$this
->
currentPage
<
$totlePage
) {
186
$ncp
=
$this
->
currentPage
+
1
;
187
$returnValue
=
$returnValue
.
"
<A href='?
"
.
$querystring
.
$this
->
pageKey
.
"
=
"
.
$ncp
.
"
'><img src='
"
.
$this
->
activeNext
.
"
' border='0'></A> \n
"
;
188
}
else
{
189
$returnValue
=
$returnValue
.
"
<img src='
"
.
$this
->
noneNext
.
"
' border='0'>\n
"
;
190
}
191
192
$returnValue
=
$returnValue
.
"
直接到第 <input id='
"
.
$this
->
pageKey
.
"
' name='
"
.
$this
->
pageKey
.
"
' size='3'; style='height:16px'> 页\n
效果图。
下载
http://www.blogjava.net/Files/jackstudio/Page.rar
posted on 2006-10-26 16:27
jackstudio 阅读(583)
评论(0) 编辑 收藏 所属分类:
common 、
asp 、
php