ASP与数据库
ASP与数据库运用:密码验证
Microsoft的大作ASP(ActiveServer
Pages)以其易学易用、扩充性好、功能多而强等优点正掀起一场新的web编程革命(从严格意义上讲,编写asp并不是编程),它以令人吃惊的发展和普及速度大有取代由perl等语言编写的CGI(Common
GatewayInterface,通用网关接口)的势头。基于web
page方式的web管理模式已经成为潮流,看看现在的网管们,有谁不会asp的编写呢?要管理?那你可能就要用到我这里要说的“密码验证”了。简单地说,密码验证就是首先判断你是不是有登录权限,如果有,就继续,否则,哼哼……。什么?你到现在还不知道ASP是什么东东?“该程序执行了非法操作,即将被关闭。如仍有问题,请与程序供应商联系。”----------系统语
下面,我们就来看看实现密码验证的ASP需要些什么吧。
一、ASP运行环境:
Windows95/98单机平台:PWS(PersonalWebServer)4.0、windowsNT
4.0/5.0服务器平台:IIS(InternetInformationServer)ServicePack3及其以上版本)
NTworkstation4.0工作站平台:PWS(PersonalWebServer)NT
workstation版及最新版的IE浏览器。
二、用于制作ASP的软件
WindowsFrontPage98/2000、Dreamweaver3.0,如果这些软件你都没有,那你就用windows
中的Notepad
当一次“代码编写狂”吧。不过ASP中很多代码仍是需要我们手工编写大量代码的,用专用的网页制作软件只不过是偷一丁点懒而已。
三、用哪一种数据库作为储存用户资料(用户名及密码)的数据库呢?
SQLServer、MicrosoftAccess
97/2000等都可以。本人建议你使用Access,因为你可能对它比较熟悉,一旦有问题,解决起来比较容易,更深的原因是:Microsoft
Access相对于其它非服务器等级的数据库执行的效率要高得多。
好了,废话说了这么多,可能你早已经不耐烦了。不过,这对于一些ASP的初学者可能还是有帮助的,对于这部分读者,你们可能还得要看看关于ASP方面的书籍或网站来增加你对ASP基本语法的了解。
让我们一步一步来做这个密码验证吧,我采用的是Windows98+PWS4.0平台,IE
5.0浏览器,网页制作软件:FrontPage2000.Go!
一、创建用户密码数据库
先用Access建立一个用户密码数据库,建立字段名id和psd,并添加值.如:id的值我设为:admin,psd的值为:www,当然,你还可以继续添加用户id及psd,完成后保存为:psd.mdb。
二、编写psd.asp(用户登录界面页,完成验证的功臣就是它了)及log.asp(成功登录后显示的页面)。在编写之前,我们来分析一下常见的用户登录界面,比如说你想收取基于web
page方式免费邮件箱的登录界面:管理用户登录的文件名常常为log.*,开始登录时是这个文件,登录完成后浏览器的地址栏中还是显示的这个文件名,这是怎么回事儿呢?用ASP的方法来讲,原来,用户登录的文件被包含在登录完成后的文件中。以我现在要讲的这个例子来说,psd.asp就是被包含在log.asp中了。用户登录时看到的文件名将是:log.asp,而log.asp要求系统先执行psd.asp,通过验证之后才看到真正的log.asp网页。对了!实际上密码验证的关键在psd.asp。在你读完本文后,你会深深体会这一点。既然psd.asp文件是关键,那我们就先来看看psd.asp是怎么写的。
运行FrontPage新建一个文件,并保存为:psd.asp(在FrontPage的保存类型中选取“ActiveServer
Pages”)。在FrontPage
左下角选取“HTML”先在它的顶部进行ASP源代码的编写,内容如下(以下源代码中凡出现“‘……”的均为注释):
<%
functioncheckPwd(id,psd)'检测用户id及密码
dimconn,param,rs
setconn=server.createobject("adodb.connection")'创建数据库连接对象conn
param="driver={microsoftaccessdriver(*.mdb)}"
‘指定数据库驱动程序,不可省略写为“accessdiver(*.mdb)”
conn.openparam&";dbq="&server.mappath("psd.mdb")
'用指定的数据库驱动程序打开数据库,并指定数据路径
sql="select*frompsdwhereid='"&id&"'andpsd='"&psd&"'"
‘定义sql从数据库中读取id及psd的值,本行中的第一个psd是指数据库名,以后的psd是指psd.mdb中的psd字段。
setrs=conn.execute(sql)'打开数据库
ifrs.eofthen
checkpwd=false
else
checkpwd=true
endif
endfunction
‘以上几句判断是否已经读完数据库中的记录,如果没有,就向后读,如果已经完成,则验证用户名及密码。如果验证通过,则为true,反之为flase
%>
<%
ifisEmpty(session("passed"))thensession("passed")=false
'判断用户输入信息
id=request("id")‘获取用户id(用户名)
psd=request("psd")‘获取用户psd(密码)
ifid=""orpsd=""then
response.write"请输入您的登录名及密码。"'如果用户没有输入完整的信息,返回出错信息。
elseifnotcheckpwd(id,psd)then
response.write"用户名或密码错误!<br>请检查你的用户名及密码然后再试一次!"
‘如果用户已经输入完整信息,但输入错误也返回出错信息。
elsesession("passed")=true
endif
ifnotsession("passed")then%>
‘用户输入的信息完全正确并验证通过,以下开始编写html代码,做一个用户登录界面。
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;
charset=gb2312">
<title>请您输入您的用户名及密码!</title>
</head>
<bodybgcolor="#000000"text="#FFFFFF">
<palign="center">
<palign="center"></p>
<palign="center"><b><fontface="黑体"
size="6">用户登录首页</font></b></p>
<palign="center"></p>
<formmethod="POST"
action="<%=request.serverVariables("psd.mdb")%>">
<tableborder="0"width="100%"cellspacing="0"cellpadding="0">
<tr>
<tdwidth="41%"align="right">用户名:</td>
<tdwidth="59%"><inputtype="text"name="id"size="20"
value="<%=id%>"></td>
</tr>
<tr>
<tdwidth="41%"align="right">密码:</td>
<tdwidth="59%"><inputtype="password"name="psd"size="20"
value="<%=psd%>"></td>
</tr>
<tr>
<tdwidth="41%"></td>
<tdwidth="59%"></td>
</tr>
</table>
<palign="center"><inputtype="submit"value="提交"name="B1"><input
type="reset"value="清除"name="B1"></p>
</form>
<%response.end
endif%>‘验证过程结束,进入加密网页。
</body>
</html>
完成了psd.asp的编写,可能你早已经迫不及待地想知道log.asp怎么编写了吧。让我们继续吧!
Log.asp的内容:
<>
‘在log.asp源代码中的顶部输入这句,作用就是在系统执行log.asp之前先执行psd.asp啦!
<html>
<head>
<title>用户验证通过,您已经成功登录系统</title>
</head>
<body><center><p><p><p><p>用户验证通过,您已经成功登录!<br>
现在你可以进行你想要的操作了。如果你有什么问题,请来信Email<a
href="mailto:kanwo@163.net?subject=问你几个关于密码验证的问题">kanwo@163.net</a></center>
</body>
</html>
呵呵……手写了这么多,还受得了吧。你在编写完成之后,可以移植到其它平台上,比如Windows
NT。最后,将你做的这两个asp文件及psd.mdb数据库放在同一个目录下(该目录必须在PWS或IIS中有www服务),比如:c:inetpubwwwroot。然后,在确保你的PWS或IIS在运行的情况下,在你们IE浏览器的地址栏中输入http://127.0.0.1/log.asp,看看,会有什么!(如果你在登录过程中听到你的硬盘在响,可别吓着了哟!)
q文章点评3篇
>>上篇文章:ASP技术访问WEB数据库
>>下篇文章:制作有管理功能的ASP留言板
第三招:控制你的弹出窗口只弹出一次(如果每进一次,刷新一次就弹出你不觉得很烦和麻烦吗?)有什么好的办法吗?
那是当然的啊,我们现在只要使用cookie来控制就能实现这样的要求了。
首先,你需把将如下代码加入到页面HTML的<HEAD>和</HEAD>之间:
<script>
.functionopenwin(){
.window.open("pop1.html","","width=120,height=240")
.}
.functionget_cookie(Name){
.varsearch=Name+"="
.varreturnvalue="";
.if(document.cookie.length>0){
.offset=document.cookie.indexOf(search)
.if(offset!=-1){
.offset+=search.length
.end=document.cookie.indexOf(";",offset);
.if(end==-1)
.end=document.cookie.length;
.returnvalue=unescape(document.cookie.substring(offset,end))
.}
.}
.returnreturnvalue;
.}
.functionloadpopup(){//*控制弹出窗口的函数哟,你要使用他的啊
.if(get_cookie('popped')==''){
.openwin()
.document.cookie="popped=yes"
.}
.}
.//-->
</script>
然后,用<bodyonload="loadpopup()">替换页面中原来的<BODY>这一句就行的了。
》》》》》》》》》》》》》》》》》》》》》》----------------------------------
在提交帖之后:
<%
ifResponse.Cookies("time")<>""then
ifDateDiff('s',Response.Cookies("time"),now())<20'隔20s才能再发帖
Response.Write"<script>alert('不能频繁发帖');window.location=history.go(-1)</script>"
response.End
endif
endif
Response.Cookies("time")=now()
……'将帖子入库
----------------------------------------------------------
ASP项目中的公共翻页模块:
在大型的ASP项目中,很多的页面都涉及到翻页功能。如果每个页面都写一个翻页的程序的话,这样的工作即降低了工作效率,也不利于工程的模块化,不能使代码重用。因此,把翻页这样的功能模块化是很有必要的。
设计方法:
1、调用该模块时,只需要传递记录集和每页显示的记录的条数;
2、可以点击链接进行翻页,也可以直接输入页码,回车后翻页;
3、不要考虑文件名,程序的每次翻页都能在当前页面。
想清楚了上面3个问题,我们的公共翻页模块就可以动手了。
<%
'+++++++++++++++++++++++++++++++++++++
'◆模块名称:公共翻页模块
'◆文件名:TurnPage.asp
'◆传入参数:Rs_tmp(记录集),PageSize(每页显示的记录条数)
'◆输出:记录集翻页显示功能
'+++++++++++++++++++++++++++++++++++++
'
SubTurnPage(ByRefRs_tmp,PageSize)'Rs_tmp记录集PageSize每页显示的记录条数;
DimTotalPage'总页数
DimPageNo'当前显示的是第几页
DimRecordCount'总记录条数
Rs_tmp.PageSize=PageSize
RecordCount=Rs_tmp.RecordCount
TotalPage=INT(RecordCount/PageSize*-1)*-1
PageNo=Request.QueryString("PageNo")
'直接输入页数跳转;
IfRequest.Form("PageNo")<>""ThenPageNo=Request.Form("PageNo")
'如果没有选择第几页,则默认显示第一页;
IfPageNo=""thenPageNo=1
IfRecordCount<>0then
Rs_tmp.AbsolutePage=PageNo
EndIf
'获取当前文件名,使得每次翻页都在当前页面进行;
DimfileName,postion
fileName=Request.ServerVariables("script_name")
postion=InstrRev(fileName,"/")+1
'取得当前的文件名称,使翻页的链接指向当前文件;
fileName=Mid(fileName,postion)
%>
<tableborder=0width='100%'>
<tr>
<tdalign=left>总页数:<fontcolor=#ff3333><%=TotalPage%></font>页
当前第<fontcolor=#ff3333><%=PageNo%></font>页</td>
<tdalign="right">
<%IfRecordCount=0orTotalPage=1Then
Response.Write"首页|前页|后页|末页"
Else%>
<ahref="<%=fileName%>?PageNo=1">首页|</a>
<%IfPageNo-1=0Then
Response.Write"前页|"
Else%>
<ahref="<%=fileName%>?PageNo=<%=PageNo-1%>">前页|</a>
<%EndIf
IfPageNo+1>TotalPageThen
Response.Write"后页|"
Else%>
<ahref="<%=fileName%>?PageNo=<%=PageNo+1%>">后页|</a>
<%EndIf%>
<ahref="<%=fileName%>?PageNo=<%=TotalPage%>">末页</a>
<%EndIf%></td>
<tdwidth=95>转到第
<%IfTotalPage=1Then%>
<inputtype=textname=PageNosize=3readonlydisabledstyle="background:#d3d3d3">
<%Else%>
<inputtype=textname=PageNosize=3value=""title=请输入页号,然后回车>
<%EndIf%>页
</td>
</tr>
</table>
<%EndSub%>
当然,大家可以把翻页的链接做成图片按钮,这样的话也面就更加美观了。
调用方法:
1、在程序开始或要使用翻页的地方包含翻页模块文件;
2、定义变量:RowCount,每页显示的记录条数
3、调用翻页过程:CallTurnPage(记录集,RowCount)
4、在DoWhile循环输出记录集的条件中加上"RowCount>0"条件
5、在循环结束"Loop前"加上:RowCount=RowCount-1
'-----------------------------------------------------
调用范例:
文件名:News.asp
<%
DimConn,Rs_News
SetConn=server.CreateObject("ADODB.CONNECTION")
Conn.Open"cpm","cpm","cpm"
DimSql
Sql="Select*fromNews"
SetRs_News=Server.CreateObject("ADODB.RECORDSET")
Rs_News.OpenSql,Conn,1,3'获取的记录集
'公共翻页模块开始%>
<>
<%
DimRowCount
RowCount=10'每页显示的记录条数
CallTurnPage(Rs_News,RowCount)
'公共翻页模块结束%>
<tablewidth=100%>
<tr>
<td>新闻编号</td>
<td>新闻标题</td>
<td>发布日期</td>
<tr>
<%
IfNotRs_News.eof
DowhileNotRs_News.eofandRowCount>0
%>
<tr>
<td><%=Rs_News("ID")%></td>
<td><%=Rs_News("Name")%></td>
<td><%=Rs_News("Date")%></td>
<tr>
<%
RowCount=RowCount-1
Rs_News.MoveNext
Loop
EndIf
%>
(出处:www.dev-club.com)
--------------------------------------------------------------------
在提交帖之后:
<%
ifResponse.Cookies("time")<>""then
ifDateDiff('s',Response.Cookies("time"),now())<20'隔20s才能再发帖
Response.Write"<script>alert('不能频繁发帖');window.location=history.go(-1)</script>"
response.End
endif
endif
Response.Cookies("time")=now()
……'将帖子入库
---------------------------------
怎样去除执行window.close()后弹出的‘是否关闭窗口'对话框
self.opener=null;
self.close();
但是只能在IE5.5或IE6.0上用
最小化、最大化、关闭窗口
<objectid=hh1classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<paramname="Command"value="Minimize"></object>
<objectid=hh2classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<paramname="Command"value="Maximize"></object>
<OBJECTid=hh3classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<PARAMNAME="Command"value="Close"></OBJECT>
-------------------------------------------------------
我的下拉框中又两个选项,当选择第一个时,出现一个用户输入页面,但是有一部分input框是不要用户填写的。当选择第二项时,出现地页面是全部都要填写的。不知道该如何实现?
<selectonchange="text1.disabled=this.selectedIndex==0">
<option>False</option>
<option>True</option>
</select>
<inputtype=textid=text1disabled>
------------------------------------------------------------------>>>>>>>>>>>>>>
我的目的是:打开一个web页(就称为'原页'吧),点击一个按钮弹出一个小窗口(原页不关,小窗口最好可以拖动),在小窗口里提交一个表单到原页。有什么方法可以实现?
给『原页』一个name属性,表单的target指向它
<script>
this.name="bencalie";
newwin=window.open("","","width=400,height=200");
newwin.document.write("<formaction='test.cgi'target='bencalie'><inputtype=submit></form>");
</script>
<<<<<<<<<<<<<<<<<<<<<<<==============================================
没有边框的窗口::;;;;
<HTMLXMLNS:IE>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<IE:DownloadID="include"STYLE="behavior:url(#default#download)"/>
<title>ChromelessWindow</title>
<SCRIPTLANGUAGE="JScript">
/*---SpecialThanksForandot---*/
/*
ThisfollowingcodearedesignedandwritenbyWindy_sk<seasonx@163.net>
Youcanuseitfreely,butumustheldallthecopyrightitems!
*/
/*---ThanksForandotAgain---*/
varCW_width=400;
varCW_height=300;
varCW_top=100;
varCW_left=100;
varCW_url="http://www.cnbruce.com/bluebook/";
varNew_CW=window.createPopup();
varCW_Body=New_CW.document.body;
varcontent="";
varCSStext="margin:1px;color:black;border:2pxoutset;border-style:expression(onmouseout=onmouseup=function(){this.style.borderStyle='outset'},onmousedown=function(){if(event.button!=2)this.style.borderStyle='inset'});background-color:buttonface;width:16px;height:14px;font-size:12px;line-height:11px;cursor:Default;";
//BuildWindow
include.startDownload(CW_url,function(source){content=source});
functioninsert_content(){
vartemp="";
CW_Body.style.overflow="hidden";
CW_Body.style.backgroundColor="white";
CW_Body.style.border="solidblack1px";
content=content.replace(/<a([^>]*)>/g,"<aonclick='parent.open(this.href);returnfalse'$1>");
temp+="<tablewidth=100%height=100%cellpadding=0cellspacing=0border=0>";
temp+="<trstyle=';font-size:12px;background:#0099CC;height:20;cursor:default'ondblclick="Max.innerText=Max.innerText=='1'?'2':'1';parent.if_max=!parent.if_max;parent.show_CW();"onmouseup='parent.drag_up(event)'onmousemove='parent.drag_move(event)'onmousedown='parent.drag_down(event)'onselectstart='returnfalse'oncontextmenu='returnfalse'>";
temp+="<tdstyle='color:#ffffff;padding-left:5px'>ChromelessWindowForIE6SP1</td>";
temp+="<tdstyle='color:#ffffff;padding-right:5px;'align=right>";
temp+="<spanid=Helponclick="alert('ChromelessWindowForIE6SP1-Ver1.0nnCodeByWindy_sknnSpecialThanksForandot')"style=""+CSStext+"font-family:System;padding-right:2px;">?</span>";
temp+="<spanid=Minonclick='parent.New_CW.hide();parent.blur()'style=""+CSStext+"font-family:Webdings;"title='Minimum'>0</span>";
temp+="<spanid=Maxonclick="this.innerText=this.innerText=='1'?'2':'1';parent.if_max=!parent.if_max;parent.show_CW();"style=""+CSStext+"font-family:Webdings;"title='Maximum'>1</span>";
temp+="<spanid=Closeonclick='parent.opener=null;parent.close()'style=""+CSStext+"font-family:System;padding-right:2px;"title='Close'>x</span>";
temp+="</td></tr><tr><tdcolspan=2>";
temp+="<divid=includestyle='overflow:scroll;overflow-x:hidden;overflow-y:auto;HEIGHT:100%;width:"+CW_width+"'>";
temp+=content;
temp+="</div>";
temp+="</td></tr></table>";
CW_Body.innerHTML=temp;
}
setTimeout("insert_content()",1000);
varif_max=true;
functionshow_CW(){
window.moveTo(10000,10000);
if(if_max){
New_CW.show(CW_top,CW_left,CW_width,CW_height);
if(typeof(New_CW.document.all.include)!="undefined"){
New_CW.document.all.include.style.width=CW_width;
New_CW.document.all.Max.innerText="1";
}
}else{
New_CW.show(0,0,screen.width,screen.height);
New_CW.document.all.include.style.width=screen.width;
}
}
window.onfocus=show_CW;
window.onresize=show_CW;
//MoveWindow
vardrag_x,drag_y,draging=false
functiondrag_move(e){
if(draging){
New_CW.show(e.screenX-drag_x,e.screenY-drag_y,CW_width,CW_height);
returnfalse;
}
}
functiondrag_down(e){
if(e.button==2)return;
if(New_CW.document.body.offsetWidth==screen.width&&New_CW.document.body.offsetHeight==screen.height)return;
drag_x=e.clientX;
drag_y=e.clientY;
draging=true;
e.srcElement.setCapture();
}
functiondrag_up(e){
draging=false;
e.srcElement.releaseCapture();
if(New_CW.document.body.offsetWidth==screen.width&&New_CW.document.body.offsetHeight==screen.height)return;
CW_top=e.screenX-drag_x;
CW_left=e.screenY-drag_y;
}
</SCRIPT>
</HTML>
============================================================>>>>>>>>>>>>>>>>>>>>>
还有图片的“黑白转彩色”
<SCRIPT>
functiondoTrans(filterCode)
{
imgObj.filters[0].apply();
oImg.style.filter=filterCode
imgObj.filters[0].play();
}
</SCRIPT>
<SPANid=imgObj
onmouseleave='doTrans("gray")'
style="FILTER:progid:DXImageTransform.Microsoft.Fade(Overlap=1.00);WIDTH:1px"
onmouseenter='doTrans("")'>
<IMGid=oImgstyle="FILTER:gray"src="http://www.cnbruce.com/images/cnrose/a.gif">
</SPAN>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
模拟office菜单:::
:::::::::::::
<styletype="text/css">
*{font-size:12px;}
body{margin:0px;}
</style>
<scriptlanguage="JavaScript">
//OfficeXP菜单
varsub_display=false;
//颜色数组说明:此数组储存菜单各部份颜色样式,可以改变颜色值达到改变样式的效果
//值依次为:高亮背景色,高亮边框色,菜单栏背景色,子菜单背景色,子菜单边框色,子菜单标题色,子菜单阴影色
varcolor=['#B6BDD2','#0A246A','#D4D0C8','#F8F8F8','#666666','#DBD8D1','#DDDDDD'];
//菜单数组说明:此数组储存各菜单数据
//值依次为:
//1.主菜单名称,下拉菜单右延空白长度
//2.第1个子菜单名称,链接地址
//3.第2个子菜单名称,链接地址
//4.......
varmenu=newArray();
menu[0]=[['菜单一',50],['1111','1.htm'],['2222','2.htm'],['3333','3.htm']];
menu[1]=[['菜单二',50],['1111','1.htm'],['2222','2.htm'],['3333','3.htm']];
menu[2]=[['菜单三',50],['1111','1.htm'],['2222','2.htm'],['3333','3.htm']];
menu[3]=[['菜单四',50],['1111','1.htm'],['2222','2.htm'],['3333','3.htm']];
menu[4]=[['菜单五',50],['1111','1.htm'],['2222','2.htm'],['3333','3.htm']];
menu[5]=[['菜单六',50],['1111','1.htm'],['2222','2.htm'],['3333','3.htm']];
document.write('<tablewidth="100%"cellspacing="0"cellpadding="0"style="background-color:'+color[2]+';border-left:1px#F4F4F4solid;border-top:1px#F4F4F4solid;border-right:1px#999999solid;border-bottom:1px#999999solid;"onSelectStart="returnfalse;"onContextMenu="returnfalse;"><tr><tdwidth="5"><imgwidth="5"height="1"></td><td><tablecellspacing="0"cellpadding="2"><tr>');
for(vari=0;i<menu.length;i++)
document.write('<tdstyle="border:1px'+color[2]+'solid;cursor:default;"onClick="Menu_Click(this,'+i+')"onMouseOver="Menu_Over(this,'+i+')"onMouseOut="Menu_Out(this,'+i+')"><nobr><imgwidth="10"height="1">'+menu[i][0][0]+'<imgwidth="10"height="1"></nobr></td>');
document.write('</td></tr></table></tr></table>');
for(vari=0;i<menu.length;i++){
document.write('<tableid="subMenu"cellspacing="0"cellpadding="0"onSelectStart="returnfalse;"onContextMenu="returnfalse;"style="position:absolute;display:none;top:1px;border-left:1px'+color[4]+'solid;border-bottom:1px'+color[4]+'solid;cursor:default;filter:progid:dximagetransform.microsoft.dropshadow(color='+color[6]+',offx=3,offy=3,positive=true)"><tr><tdstyle="border-top:1px'+color[4]+'solid;border-right:1px'+color[4]+'solid;background-color:'+color[5]+';"onClick="subMenu_Hide(false)"><nobr><imgwidth="1"height="2"><br><imgwidth="12"height="1">'+menu[i][0][0]+'<imgwidth="12"height="1"><br><imgwidth="1"height="3"></nobr></td><tdstyle="border-bottom:1px'+color[4]+'solid;"onMouseOver="subMenu_Hide(true)"><imgwidth="'+menu[i][0][1]+'"height="1"></td></tr><tr><tdcolspan="2"style="border-right:1px'+color[4]+'solid;background-color:'+color[3]+';"><tablewidth="100%"cellspacing="1"cellpadding="2"style="background-color:'+color[3]+'">');
for(varj=1;j<menu[i].length;j++)
document.write('<tr><tdstyle="border:1px'+color[3]+'solid;"onMouseOver="subMenu_Over(this)"onMouseOut="subMenu_Out(this)"onClick="location.href=''+menu[i][j][1]+''"><nobr>'+menu[i][j][0]+'</nobr></td></tr>');
document.write('</td></tr></table></td></tr></table>');
}
functionMenu_Over(obj,s){
if(sub_display){
subMenu_Show(obj,s)
}
else{
obj.style.backgroundColor=color[0];
obj.style.border='1px'+color[1]+'solid';
}
}
functionMenu_Out(obj){
obj.style.backgroundColor='';
obj.style.border='1px'+color[2]+'solid';
}
functionMenu_Click(obj,s){
subMenu_Show(obj,s)
}
functionsubMenu_Over(obj){
obj.style.backgroundColor=color[0];
obj.style.border='1px'+color[1]+'solid';
}
functionsubMenu_Out(obj){
obj.style.backgroundColor='';
obj.style.border='1px'+color[3]+'solid';
}
functionsubMenu_Hide(hide){
for(vari=0;i<subMenu.length;i++)
subMenu[i].style.display='none';
sub_display=hide;
}
functionsubMenu_Show(obj,s){
subMenu_Hide(false);
subMenu(s).style.posLeft=obj.offsetLeft+6;
subMenu(s).style.display='';
sub_display=true;
}
window.onfocus=subMenu_Hide;
</script>
=-=======================-----------------========================================
模仿OUTLOOK的菜单:
<head>
<styletype="text/css">
.titleStyle{
background-color:#3366cc;color:#ffffff;border-top:1pxsolid#FFFFFF;font-size:9pt;cursor:hand;
}
.contentStyle{
background-color:#efefef;color:blue;font-size:9pt;
}
a{
color:blue;
}
body{
font-size:9pt;
}
</style>
</head>
<body>
<scriptlanguage="JavaScript">
<)
eval('document.all.item'+i+'.style.top=parseInt(document.all.item'+i+'.style.top)+contentHeight/stepNo;');
}
changeItem(0);
//-->
</script>
</body>