扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:分析员之旅 来源:CSDN 2008年3月23日
关键字: Web开发 JavaScript VBScript 切换 Windows
一、原理说明:
1、利用Javascript构造一个HTTP请求向后台数据库请求图片路径和图片描述数据
2、利用返回的图片数据构造一个图片路径数组和图片描述数组
3、构造一个IMG对象
4、利用javascript的定时函数控制IMG对象的SRC属性和TITLE属性在图片路径数组和图片描述数组各元素之间切换
二、文件组成:
frontpage.asp
loadpicturesource.asp
conn.asp
site.MDB
三、详细设计:
1、客户端请求调用frontpage.asp: Http - > frontpage.asp
2、frontpage.asp调用loadpicturesource.asp获取图片数据:frontpage.asp - > loadpicturesource.asp
3、loadpicturesource.asp调用site.MDB获取数据存储:loadpicturesource.asp - > site.MDB
4、frontpage.asp利用调用返回数据构造图片路径数组和图片描述数组
5、frontpage.asp启动setInterval定时函数进行自动控制
四、文件内容:
============================================================================
frontpage.asp
============================================================================
<!--#include file="conn.asp"-->
<%
dim rs,sSql,sOutput,defaultPicture,defaultDescription,interval
'刷新频率
interval =5000
'默认图片和默认说明
set rs=server.CreateObject("ADODB.RecordSet")
sSql = "select top 1 * from pictureSet where PicName = '首页图片' order by updateDate desc"
rs.open sSql,conn,1,1
if not rs.bof and not rs.eof then
defaultPicture = rs("PicPath")
defaultDescription = rs("PicTiTle")
End If
rs.close
conn.close
Set rs = Nothing
Set conn = Nothing
defaultDescription = "图片新闻:"&defaultDescription&"(点击图片查看放大效果)"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript">
<!--
var arraySrc;
var arrayAlt;
var picNameCounter = 0;
function GetServerData(objstrName,objstrValue,serverPage)
{
string=escape(objstrName) +"="+escape(objstrValue);
var objXMLHTTP = null;
try
{
objXMLHTTP = new ActiveXObject("MSXML2.XMLHTTP");
}
catch(e)
{
try
{
objXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e2){}
}
objXMLHTTP.open("POST", serverPage, false);
objXMLHTTP.setrequestheader("content-length",string.length);
objXMLHTTP.setrequestheader("content-type","application/x-www-form-urlencoded");
objXMLHTTP.send(string);
return objXMLHTTP.responseText;
}
function Initialize()
{
var returnSrc = GetServerData("PictureSrc","PictureSrc","LoadDisplayPicture.asp");
arraySrc= returnSrc.split("|");
var returnAlt = GetServerData("PictureAlt","PictureAlt","LoadDisplayPicture.asp");
arrayAlt = returnAlt.split("|");
setInterval("PictureLoad()",<%=interval%>);
}
function PictureLoad()
{
document.all('mainpic').src = arraySrc[picNameCounter].toString();
document.all('mainpic').title = arrayAlt[picNameCounter].toString();
document.all('pictureDescption').innerText = "图片新闻:" + arrayAlt[picNameCounter].toString() + "(点击图片查看放大效果)";
picNameCounter = picNameCounter + 1;
if (picNameCounter > 9 ||picNameCounter > arraySrc.length - 1)
{
picNameCounter = 0;
}
}
function showFull()
{
var newWin = window.open();
newWin.document.write("<img src="+ newWin.opener.mainpic.src +" title="+ newWin.opener.mainpic.title +" width=100% height = 100%>");
newWin.document.close();
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<table width="100%" height="224" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="0.5px" colspan="3" bgcolor=<%=bgColor%>> </td>
</tr>
<tr>
<td height="6" bordercolor="#000000" >
<!------------------图片切换部分------------------>
<img name = "mainpic" src = <%=defaultPicture%> width = "280" height="186" onclick = "showFull();" title=<%=defaultDescription%>>
<td width="1%" bgcolor=<%=bgColor%>></td>
<td width="65%" bordercolor="#000000" bgcolor = "#FFFFFF">
<!------------------文字新闻部分------------------>
<script language="javascript" src="owen.asp?n=7"></script>
</td>
</tr>
<tr>
<td colspan="3">
<table>
<tr>
<td align="left" width = 88%><font size = 2px><a name = "pictureDescption" ><%=defaultDescription%></a></font></td>
<td align="right"><a href = "default_all.asp" target = "_blank"><font size = 2px>更多新闻...</font></a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="0.5px" colspan="3" bgcolor=<%=bgColor%>> </td>
</tr>
</table>
<script language = javascript>Initialize();</script>
</BODY>
</HTML>
============================================================================
loadpicturesource.asp
============================================================================
<!--#include file="conn.asp"-->
<%
Response.CharSet = "gb2312"
Dim PictureSrc,PictureAlt,returnValue
PictureSrc = request("PictureSrc")
PictureAlt = request("PictureAlt")
If PictureSrc <> "" Then
'加载图片地址
set rs=server.createobject("adodb.recordset")
rs.open "select * from PictureSet where picName='首页图片' order by updateDate desc",conn,3,3
for i=1 to rs.recordcount
if i=1 then
returnValue=rs("PicPath")
else
returnValue=returnValue&"|"&rs("PicPath")
end if
rs.movenext
Next
Elseif PictureAlt <> "" Then
'加载图片描述
set rs=server.createobject("adodb.recordset")
rs.open "select * from PictureSet where picName='首页图片' order by updateDate desc",conn,3,3
for i=1 to rs.recordcount
if i=1 then
returnValue=rs("PicTitle")
else
returnValue=returnValue&"|"&rs("PicTitle")
end if
rs.movenext
Next
End If
rs.close
conn.close
Set rs = Nothing
Set conn = nothing
response.write returnValue
%>
============================================================================
conn.asp
============================================================================
<%
dim conn,connstr
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&server.mappath(".")&"\site.MDB;Persist Security Info=False"
Set conn=Server.CreateObject("ADODB.CONNECTION")
conn.open connstr
%>
============================================================================
site.MDB
============================================================================
create table PictureSet
(
id int identity,
picName varchar(20),
picPath varchar(50),
picTitle varchar(50),
updateDate datetime
)
insert into PictureSet(picName,picPath,picTitle,updateDate) values('首页图片','./pictureSource/autoDisplay_1.jpg','图片说明','2006-06-17')
insert into PictureSet(picName,picPath,picTitle,updateDate) values('首页图片','./pictureSource/autoDisplay_2.jpg','图片说明','2006-06-17')
insert into PictureSet(picName,picPath,picTitle,updateDate) values('首页图片','./pictureSource/autoDisplay_3.jpg','图片说明','2006-06-17')
insert into PictureSet(picName,picPath,picTitle,updateDate) values('首页图片','./pictureSource/autoDisplay_4.jpg','图片说明','2006-06-17')
insert into PictureSet(picName,picPath,picTitle,updateDate) values('首页图片','./pictureSource/autoDisplay_5.jpg','图片说明','2006-06-17')
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者