08-03
12

div + ajax + 分页函数

list.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>default</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
*
{
margin:0;
padding:0;
}
#contain
{
width:770px;
margin:10px auto;
}
#header
{
width:768px;
border:1px solid #eeaaee;
margin-bottom:10px;
height:100px;
}
#main
{
width:770px;
margin-bottom:10px;
}
#main_L
{
width:148px;
border:1px solid #eeaaee;
float:left;
margin-right:10px;
height:400px;
}
#main_M
{
width:348px;
border:1px solid #eeaaee;
float:left;
margin-right:10px;
height:400px;
}
#main_R
{
width:248px;
border:1px solid #eeaaee;
float:left;
height:300px;
}
#footer
{
width:768px;
border:1px solid #eeaaee;
height:40px;
}

</style>

</head>

<body onLoad="FF()">

<div id="contain">
<div id="header">rr</div>
<div id="main">
<div id="main_L">rr</div>
<div id="main_M"></div>
<div id="main_R">rr</div>
<br style="clear:both">
</div>
<div id="footer">rr</div>
</div>
<script type="text/javascript">
function FF(y) {
if (!y) {
y=1;
}
var xmlhttp;
if (window.ActiveXObject) {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
}
if (xmlhttp) {
xmlhttp.onreadystatechange=function () {
if(xmlhttp.readyState==4) {
if(xmlhttp.status==200) {
var yy=unescape(xmlhttp.responseText);
show(yy);
}else {
alert("error");
}
}
}
xmlhttp.open("get","page.asp?page="+y);
xmlhttp.send(null);
}
}
function show(text) {
document.getElementById("main_M").innerHTML=text;
}
</script>
</body>
</html>

page.asp
<%
dim conn,rs
dim connstr,sqlcmd
set conn=server.CreateObject("ADODB.connection")
connstr="Driver={Microsoft Access Driver (*.mdb)};dbq="&server.MapPath("mydata.mdb")
conn.open connstr
sqlcmd="s e lect id,name,tel from contact"
set rs=server.CreateObject("ADODB.recordset")
rs.open sqlcmd,conn,1,1
rs.pagesize=6
page=clng(request.QueryString("page"))
if page<1 then page=1
if page>rs.pagecount then page=rs.pagecount
rs.absolutepage=page
response.Write("<table width='300px' border='1'>")
for i=1 to rs.pagesize
response.Write("<tr>")
response.Write("<td>"&rs(0)&"</td>")
response.Write("<td>"&escape(rs(1))&"</td>")
response.Write("<td>"&rs(2)&"</td>")
response.Write("</tr>")
rs.movenext
if rs.EOF then exit for
next
response.Write("</table>")

if page=1 then
response.write(escape("首页 上一页"))
response.write("<a href='javascript:FF("&(page+1)&")'>"&escape("下一页")&"</a>")
response.write("<a href='javascript:FF("&rs.pagecount&")'>"&escape("末页")&"</a>")
elseif page=rs.pagecount then
response.write("<a href='javascript:FF(1)'>"&escape("首页")&"</a>")
response.write("<a href='javascript:FF("&(page-1)&")'>"&escape("上一页")&"</a>")
response.write(escape("下一页 末页"))
else
response.write("<a href='javascript:FF(1)'>"&escape("首页")&"</a>")
response.write("<a href='javascript:FF("&(page-1)&")'>"&escape("上一页")&"</a>")
response.write("<a href='javascript:FF("&(page+1)&")'>"&escape("下一页")&"</a>")
response.write("<a href='javascript:FF("&rs.pagecount&")'>"&escape("末页")&"</a>")
end if
%>


文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: ASP 分页 DIV
相关日志:
评论: 0 | 引用: 0 | 查看次数: 579
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭