当前位置: 移动技术网 > IT编程>开发语言>Asp > ASP与数据库,有用的代码(转贴,摘贴)

ASP与数据库,有用的代码(转贴,摘贴)

2017年12月12日  | 移动技术网IT编程  | 我要评论
asp与数据库  asp与数据库运用:密码验证          microsoft 的大作asp(active server&nb
asp与数据库

 asp与数据库运用:密码验证 
        microsoft 的大作asp(active server 
      pages)以其易学易用、扩充性好、功能多而强等优点正掀起一场新的web编程革命(从严格意义上讲,编写asp并不是编程),它以令人吃惊的发展和普及速度大有取代由perl等语言编写的cgi(common 
      gateway interface,通用网关接口) 的势头。基于web 
      page方式的web管理模式已经成为潮流,看看现在的网管们,有谁不会asp的编写呢?要管理?那你可能就要用到我这里要说的“密码验证”了。简单地说,密码验证就是首先判断你是不是有登录权限,如果有,就继续,否则,哼哼……。什么?你到现在还不知道asp是什么东东?“该程序执行了非法操作,即将被关闭。如仍有问题,请与程序供应商联系。”----------系统语
        下面,我们就来看看实现密码验证的asp需要些什么吧。
        一、 asp运行环境:
        windows 95/98单机平台:pws (personal web server)4.0 、windows nt 
      4.0/5.0服务器平台:iis(internet information server )service pack 3 及其以上版本)
        nt workstation 4.0 工作站平台:pws(personal web server )nt 
      workstation版及最新版的ie浏览器。
        二、 用于制作asp的软件
        windows frontpage 98/2000 、dreamweaver 3.0 ,如果这些软件你都没有,那你就用windows 
      中的notepad 
      当一次“代码编写狂”吧。不过asp中很多代码仍是需要我们手工编写大量代码的,用专用的网页制作软件只不过是偷一丁点懒而已。
        三、 用哪一种数据库作为储存用户资料(用户名及密码)的数据库呢?
        sql server、microsoft access 
      97/2000等都可以。本人建议你使用access,因为你可能对它比较熟悉,一旦有问题,解决起来比较容易,更深的原因是:microsoft 
      access相对于其它非服务器等级的数据库执行的效率要高得多。
        好了,废话说了这么多,可能你早已经不耐烦了。不过,这对于一些asp的初学者可能还是有帮助的,对于这部分读者,你们可能还得要看看关于asp方面的书籍或网站来增加你对asp基本语法的了解。
        让我们一步一步来做这个密码验证吧,我采用的是windows 98 + pws 4.0平台,ie 
      5.0浏览器,网页制作软件:frontpage 2000. 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 的保存类型中选取“active server 
      pages”)。在frontpage 
      左下角选取“html”先在它的顶部进行asp源代码的编写,内容如下(以下源代码中凡出现“‘……”的均为注释): 
        <%
        function checkpwd(id,psd) '检测用户id及密码
        dim conn,param,rs 
        set conn=server.createobject("adodb.connection") '创建数据库连接对象conn
        param="driver={microsoft access driver (*.mdb)}" 
      ‘指定数据库驱动程序,不可省略写为“access diver(*.mdb)”
        conn.open param & ";dbq=" & server.mappath("psd.mdb") 
      '用指定的数据库驱动程序打开数据库,并指定数据路径
        sql="select*from psd where id='" & id & "' and psd='" & psd & "'" 
      ‘定义sql从数据库中读取id及psd的值,本行中的第一个psd是指数据库名,以后的psd是指psd.mdb中的psd字段。
        set rs=conn.execute(sql) '打开数据库
        if rs.eof then 
        checkpwd=false 
        else 
        checkpwd=true 
        end if 
        end function 
      ‘以上几句判断是否已经读完数据库中的记录,如果没有,就向后读,如果已经完成,则验证用户名及密码。如果验证通过,则为true,反之为flase
        %> 
        <% 
        if isempty(session("passed")) then session("passed")=false 
      '判断用户输入信息 
        id=request("id") ‘获取用户id(用户名)
        psd=request("psd") ‘获取用户psd(密码)
        if id="" or psd="" then 
        response.write"请输入您的登录名及密码。" '如果用户没有输入完整的信息,返回出错信息。 
        elseif not checkpwd(id,psd) then 
        response.write"用户名或密码错误!<br>请检查你的用户名及密码然后再试一次!" 
      ‘如果用户已经输入完整信息,但输入错误也返回出错信息。
        else session("passed")=true 
        end if
        if not session("passed") then%> 
      ‘用户输入的信息完全正确并验证通过,以下开始编写html代码,做一个用户登录界面。
        <html>
        <head>
        <meta http-equiv="content-type" content="text/html; 
      charset=gb2312">
        <title>请您输入您的用户名及密码!</title>
        </head>
        <body bgcolor="#000000" text="#ffffff">
        <p align="center">  
        <p align="center"> </p> 
        <p align="center"><b><font face="黑体" 
      size="6">用户登录首页</font></b></p> 
        <p align="center"> </p> 
        <form method="post" 
      action="<%=request.servervariables("psd.mdb")%>"> 
        <table border="0" width="100%" cellspacing="0" cellpadding="0"> 
        <tr> 
        <td width="41%" align="right">用户名:</td> 
        <td width="59%"><input type="text" name="id" size="20" 
      value="<%=id%>"></td> 
        </tr> 
        <tr> 
        <td width="41%" align="right"> 密 码:</td> 
        <td width="59%"><input type="password" name="psd" size="20" 
      value="<%=psd%>"></td> 
        </tr> 
        <tr> 
        <td width="41%"> </td> 
        <td width="59%"> </td> 
        </tr> 
        </table> 
        <p align="center"><input type="submit" value="提交" name="b1"><input 
      type="reset" value="清除" name="b1"></p> 
        </form> 
        <%response.end 
        end if %> ‘验证过程结束,进入加密网页。
        </body> 
        </html> 
        完成了psd.asp的编写,可能你早已经迫不及待地想知道log.asp怎么编写了吧。让我们继续吧!
        log.asp的内容:
        <!--#include file="psd.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:\inetpub\wwwroot\。然后,在确保你的pws或iis在运行的情况下,在你们ie浏览器的地址栏中输入http://127.0.0.1/log.asp,看看,会有什么!(如果你在登录过程中听到你的硬盘在响,可别吓着了哟!)

 


q 文 章 点 评       3 篇


>>上篇文章:asp技术访问web数据库  
>>下篇文章:制作有管理功能的asp留言板  



 

第三招:控制你的弹出窗口只弹出一次(如果每进一次,刷新一次就弹出你不觉得很烦和麻烦吗?)有什么好的办法吗?
那是当然的啊,我们现在只要使用cookie来控制就能实现这样的要求了。
首先,你需把将如下代码加入到页面html的<head>和</head>之间:

<script>
.function openwin(){
.window.open("pop1.html","","width=120,height=240")
.}
.function get_cookie(name) {
.var search = name + "="
.var returnvalue = "";
.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))
. }
. }
.return returnvalue;
. }
.function loadpopup(){ //*控制弹出窗口的函数哟,你要使用他的啊
.if (get_cookie('popped')==''){
.openwin()
.document.cookie="popped=yes"
. }
.}
.//-->
</script>

 然后,用<body onload="loadpopup()">替换页面中原来的<body>这一句就行的了。


》》》》》》》》》》》》》》》》》》》》》》----------------------------------
在提交帖之后:
<%
if response.cookies("time")<>"" then
  if datediff('s',response.cookies("time"),now())<20   '隔20s才能再发帖
    response.write "<script>alert('不能频繁发帖');window.location=history.go(-1)</script>"
    response.end
  end if
end if
response.cookies("time")=now()
……             '将帖子入库
----------------------------------------------------------

                    asp项目中的公共翻页模块:

在大型的asp项目中,很多的页面都涉及到翻页功能。如果每个页面都写一个翻页的程序的话,这样的工作即降低了工作效率,也不利于工程的模块化,不能使代码重用。因此,把翻页这样的功能模块化是很有必要的。
设计方法: 
1、调用该模块时,只需要传递记录集和每页显示的记录的条数; 
2、可以点击链接进行翻页,也可以直接输入页码,回车后翻页; 
3、不要考虑文件名,程序的每次翻页都能在当前页面。 
想清楚了上面3个问题,我们的公共翻页模块就可以动手了。 
<% 
'+++++++++++++++++++++++++++++++++++++ 
'◆模块名称: 公共翻页模块 
'◆文 件 名: turnpage.asp 
'◆传入参数: rs_tmp (记录集), pagesize (每页显示的记录条数) 
'◆输 出: 记录集翻页显示功能 
'+++++++++++++++++++++++++++++++++++++ 

sub turnpage(byref rs_tmp,pagesize) 'rs_tmp 记录集  pagesize 每页显示的记录条数; 
dim totalpage '总页数 
dim pageno '当前显示的是第几页 
dim recordcount '总记录条数 
rs_tmp.pagesize = pagesize 
recordcount = rs_tmp.recordcount 
totalpage = int(recordcount / pagesize * -1)*-1 
pageno = request.querystring ("pageno") 
'直接输入页数跳转; 
if request.form("pageno")<>"" then pageno = request.form("pageno") 
'如果没有选择第几页,则默认显示第一页; 
if pageno = "" then pageno = 1 
if recordcount <> 0 then 
rs_tmp.absolutepage = pageno 
end if 

'获取当前文件名,使得每次翻页都在当前页面进行; 
dim filename,postion 
filename = request.servervariables("script_name") 
postion = instrrev(filename,"/")+1 
'取得当前的文件名称,使翻页的链接指向当前文件; 
filename = mid(filename,postion) 
%> 
<table border=0 width='100%'> 
<tr> 
<td align=left> 总页数:<font color=#ff3333><%=totalpage%></font>页 
  当前第<font color=#ff3333><%=pageno%></font>页</td> 
<td align="right"> 
<%if recordcount = 0 or totalpage = 1 then 
response.write "首页|前页|后页|末页" 
else%> 
<a href="<%=filename%>?pageno=1">首页|</a> 
<%if pageno - 1 = 0 then 
response.write "前页|" 
else%> 
<a href="<%=filename%>?pageno=<%=pageno-1%>">前页|</a> 
<%end if 

if pageno+1 > totalpage then 
response.write "后页|" 
else%> 
<a href="<%=filename%>?pageno=<%=pageno+1%>">后页|</a> 
<%end if%> 

<a href="<%=filename%>?pageno=<%=totalpage%>">末页</a> 
<%end if%></td> 
<td width=95>转到第 
<%if totalpage = 1 then%> 
<input type=text name=pageno size=3 readonly disabled style="background:#d3d3d3"> 
<%else%> 
<input type=text name=pageno size=3 value="" title=请输入页号,然后回车> 
<%end if%>页 
</td> 
</tr> 
</table> 
<%end sub%> 

当然,大家可以把翻页的链接做成图片按钮,这样的话也面就更加美观了。 

调用方法: 
1、在程序开始或要使用翻页的地方包含翻页模块文件; 
2、定义变量:rowcount,每页显示的记录条数 
3、调用翻页过程:call turnpage(记录集,rowcount) 
4、在do while 循环输出记录集的条件中加上" rowcount > 0 " 条件 
5、在循环结束 "loop前" 加上: rowcount = rowcount - 1 

'----------------------------------------------------- 
调用范例: 
文件名:news.asp 

<% 
dim conn,rs_news 
set conn = server.createobject("adodb.connection") 
conn.open "cpm","cpm","cpm" 

dim sql 
sql = "select * from news" 
set rs_news = server.createobject("adodb.recordset") 
rs_news.open sql,conn,1,3 '获取的记录集 

'公共翻页模块开始%> 
<!--#include file=../public/turnpage.asp--> 
<% 
dim rowcount 
rowcount = 10 '每页显示的记录条数 
call turnpage(rs_news,rowcount) 
'公共翻页模块结束%> 

<table width=100%> 
<tr> 
<td>新闻编号</td> 
<td>新闻标题</td> 
<td>发布日期</td> 
<tr> 
<% 
if not rs_news.eof 
do while not rs_news.eof and rowcount>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 
end if 
%>  
(出处:www.dev-club.com)

 
 --------------------------------------------------------------------
 在提交帖之后:
<%
if response.cookies("time")<>"" then
  if datediff('s',response.cookies("time"),now())<20   '隔20s才能再发帖
    response.write "<script>alert('不能频繁发帖');window.location=history.go(-1)</script>"
    response.end
  end if
end if
response.cookies("time")=now()
……             '将帖子入库


---------------------------------
怎样去除执行window.close()后弹出的‘是否关闭窗口'对话框

self.opener=null;
self.close();
但是只能在ie5.5  或ie6.0上用

最小化、最大化、关闭窗口
<object id=hh1 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"> 
<param name="command" value="minimize"></object>
<object id=hh2 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"> 
<param name="command" value="maximize"></object>
<object id=hh3 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<param name="command" value="close"></object>
-------------------------------------------------------
我的下拉框中又两个选项,当选择第一个时,出现一个用户输入页面,但是有一部分input框是不要用户填写的。当选择第二项时,出现地页面是全部都要填写的。不知道该如何实现?
<select onchange="text1.disabled=this.selectedindex==0">
<option>false</option>
<option>true</option>
</select>
<input type=text id=text1 disabled>
------------------------------------------------------------------>>>>>>>>>>>>>>
我的目的是:打开一个web页(就称为'原页' 吧),点击一个按钮弹出一个小窗口(原页不关,小窗口最好可以拖动),在小窗口里提交一个表单到原页。有什么方法可以实现?
给『原页』一个name属性,表单的target指向它
<script>
this.name = "bencalie";
newwin = window.open("","","width=400,height=200");
newwin.document.write("<form action='test.cgi' target='bencalie'><input type=submit></form>");
</script>

<<<<<<<<<<<<<<<<<<<<<<<==============================================
没有边框的窗口::;;;;

<html  xmlns:ie>
<meta  http-equiv="content-type"  content="text/html;  charset=gb2312">
<ie:download  id="include"  style="behavior:url(#default#download)"  />
<title>chromeless  window</title>

<script  language="jscript">
/*---  special  thanks  for  andot  ---*/

/*
  this  following  code  are  designed  and  writen  by  windy_sk  <seasonx@163.net>
  you  can  use  it  freely,  but  u  must  held  all  the  copyright  items!
*/

/*---  thanks  for  andot  again  ---*/

var  cw_width =  400;
var  cw_height =  300;
var  cw_top =  100;
var  cw_left =  100;
var  cw_url =  "http://www.cnbruce.com/bluebook/";
var  new_cw =  window.createpopup();
var  cw_body =  new_cw.document.body;
var  content =  "";
var  csstext =  "margin:1px;color:black;  border:2px  outset;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;";

//build  window
include.startdownload(cw_url,  function(source){content=source});

function  insert_content(){
 var  temp  =  "";
 cw_body.style.overflow  =  "hidden";
 cw_body.style.backgroundcolor =  "white";
 cw_body.style.border  =    "solid  black  1px";
 content  =  content.replace(/<a  ([^>]*)>/g,"<a  onclick='parent.open(this.href);return  false'  $1>");
 temp  +=  "<table  width=100%  height=100%  cellpadding=0  cellspacing=0  border=0>";
 temp  +=  "<tr  style=';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='return  false'  oncontextmenu='return  false'>";
 temp  +=  "<td  style='color:#ffffff;padding-left:5px'>chromeless  window  for  ie6  sp1</td>";
 temp  +=  "<td  style='color:#ffffff;padding-right:5px;'  align=right>";
 temp  +=  "<span  id=help    onclick=\"alert('chromeless  window  for  ie6  sp1    -    ver  1.0\\n\\ncode  by  windy_sk\\n\\nspecial  thanks  for  andot')\"  style=\""+csstext+"font-family:system;padding-right:2px;\">?</span>";
 temp  +=  "<span  id=min      onclick='parent.new_cw.hide();parent.blur()'  style=\""+csstext+"font-family:webdings;\"  title='minimum'>0</span>";
 temp  +=  "<span  id=max      onclick=\"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  +=  "<span  id=close  onclick='parent.opener=null;parent.close()'  style=\""+csstext+"font-family:system;padding-right:2px;\"  title='close'>x</span>";
 temp  +=  "</td></tr><tr><td  colspan=2>";
 temp  +=  "<div  id=include  style='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);

var  if_max  =  true;
function  show_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;

//  move  window
var  drag_x,drag_y,draging=false

function  drag_move(e){
 if  (draging){
  new_cw.show(e.screenx-drag_x,  e.screeny-drag_y,  cw_width,  cw_height);
  return  false;
 }
}

function  drag_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();
}

function  drag_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>
function  dotrans(filtercode)  
{
imgobj.filters[0].apply();
oimg.style.filter  =  filtercode
imgobj.filters[0].play();
}
</script>

<span  id=imgobj  
onmouseleave='dotrans("gray")'  
style="filter:  progid:dximagetransform.microsoft.fade(overlap=1.00);  width:  1px"  
onmouseenter='dotrans("")'>
<img  id=oimg  style="filter:  gray"  src="http://www.cnbruce.com/images/cnrose/a.gif">  
</span>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
模拟office菜单:::
:::::::::::::
<style  type="text/css">
*  {  font-size:  12px;  }
body  {  margin:  0px;  }
</style>

<script  language="javascript">
//  office  xp  菜单

var  sub_display  =  false;

//  颜色数组说明:此数组储存菜单各部份颜色样式,可以改变颜色值达到改变样式的效果
//  值依次为:高亮背景色,  高亮边框色,  菜单栏背景色,  子菜单背景色,  子菜单边框色,  子菜单标题色,  子菜单阴影色

var  color  =  ['#b6bdd2',  '#0a246a',  '#d4d0c8',  '#f8f8f8',  '#666666',  '#dbd8d1',  '#dddddd'];

//  菜单数组说明:此数组储存各菜单数据
//  值依次为:
//  1.  主菜单名称,  下拉菜单右延空白长度
//  2.  第1个子菜单名称,  链接地址
//  3.  第2个子菜单名称,  链接地址
//  4.  ......

var  menu  =  new  array();
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('<table  width="100%"  cellspacing="0"  cellpadding="0"  style="background-color:  '  +  color[2]  +  ';  border-left:  1px  #f4f4f4  solid;  border-top:  1px  #f4f4f4  solid;  border-right:  1px  #999999  solid;  border-bottom:  1px  #999999  solid;"  onselectstart="return  false;"  oncontextmenu="return  false;"><tr><td  width="5"><img  width="5"  height="1"></td><td><table  cellspacing="0"  cellpadding="2"><tr>');
for  (var  i=0;  i<menu.length;  i++)
document.write('<td  style="border:  1px  '  +  color[2]  +  '  solid;  cursor:  default;"  onclick="menu_click(this,  '  +  i  +  ')"  onmouseover="menu_over(this,  '  +  i  +  ')"  onmouseout="menu_out(this,  '  +  i  +  ')"><nobr><img  width="10"  height="1">'  +  menu[i][0][0]  +  '<img  width="10"  height="1"></nobr></td>');
document.write('</td></tr></table></tr></table>');

for  (var  i=0;  i<menu.length;  i++)  {
        document.write('<table  id="submenu"  cellspacing="0"  cellpadding="0"  onselectstart="return  false;"  oncontextmenu="return  false;"  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><td  style="border-top:  1px  '  +  color[4]  +  '  solid;  border-right:  1px  '  +  color[4]  +  '  solid;  background-color:  '  +  color[5]  +  ';"  onclick="submenu_hide(false)"><nobr><img  width="1"  height="2"><br><img  width="12"  height="1">'  +  menu[i][0][0]  +  '<img  width="12"  height="1"><br><img  width="1"  height="3"></nobr></td><td  style="border-bottom:  1px  '  +  color[4]  +  '  solid;"  onmouseover="submenu_hide(true)"><img  width="'  +  menu[i][0][1]  +  '"  height="1"></td></tr><tr><td  colspan="2"  style="border-right:  1px  '  +  color[4]  +  '  solid;  background-color:  '  +  color[3]  +  ';"><table  width="100%"  cellspacing="1"  cellpadding="2"  style="  background-color:  '  +  color[3]  +  '">');
        for  (var  j=1;  j<menu[i].length;  j++)
        document.write('<tr><td  style="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>');
}

function  menu_over(obj,  s)  {
        if  (sub_display)  {
                submenu_show(obj,  s)
        }
        else  {
                obj.style.backgroundcolor  =  color[0];
                obj.style.border  =  '1px  '  +  color[1]  +  '  solid';
        }
}

function  menu_out(obj)  {
        obj.style.backgroundcolor  =  '';
        obj.style.border  =  '1px  '  +  color[2]  +  '  solid';
}

function  menu_click(obj,  s)  {
        submenu_show(obj,  s)
}

function  submenu_over(obj)  {
        obj.style.backgroundcolor  =  color[0];
        obj.style.border  =  '1px  '  +  color[1]  +  '  solid';
}

function  submenu_out(obj)  {
        obj.style.backgroundcolor  =  '';
        obj.style.border  =  '1px  '  +  color[3]  +  '  solid';
}

function  submenu_hide(hide)  {
        for  (var  i=0;  i<submenu.length;  i++)
        submenu[i].style.display  =  'none';
        sub_display  =  hide;
}

function  submenu_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>
<style  type="text/css">
.titlestyle{
background-color:#3366cc;color:#ffffff;border-top:1px  solid  #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>
<script  language="javascript">
<!--
  var  layertop=20;              //菜单顶边距
  var  layerleft=30;            //菜单左边距
  var  layerwidth=140;        //菜单总宽
  var  titleheight=20;        //标题栏高度
  var  contentheight=200;  //内容区高度
  var  stepno=10;                  //移动步数,数值越大移动越慢

  var  itemno=0;runtimes=0;
  document.write('<span  id=itemslayer  style="position:absolute;overflow:hidden;border:1px  solid  #efefef;left:'+layerleft+';top:'+layertop+';width:'+layerwidth+';">');

  function  additem(itemtitle,itemcontent){
      itemhtml='<div  id=item'+itemno+'  itemindex='+itemno+'  style="position:relative;left:0;top:'+(-contentheight*itemno)+';width:'+layerwidth+';"><table  width=100%  cellspacing="0"  cellpadding="0">'+
              '<tr><td  height='+titleheight+'  onclick=changeitem('+itemno+')  class="titlestyle"  align=center>'+itemtitle+'</td></tr>'+
              '<tr><td  height='+contentheight+'  class="contentstyle">'+itemcontent+'</td></tr></table></div>';
      document.write(itemhtml);
      itemno++;
  }
        //添加菜单标题和内容,可任意多项,注意格式:
  additem('欢迎','<br>  www.cnbruce.com');
  additem('网页专区','<center><a  href="#">网页工具</a>  <br><br><a  href="#">技术平台</a>  <br><br><a  href="#">设计理念</a>  <br><br><a  href="#">更多</a></center>');
  additem('美工教室','<center><a  href="#">平面设计  </a>  <br><br><a  href="#">三维空间</a>  <br><br><a  href="#">设计基础</a>  <br><br><a  href="#">更多..</a></center>');
  additem('flash','<center><a  href="#">基础教程</a>  <br><br><a  href="#">技巧运用</a>  <br><br><a  href="#">实例剖析</a>  <br><br><a  href="#">更多..</a></center>');
  additem('多媒体','<center><a  href="#">director</a>  <br><br><a  href="#">authorware</a>  <br><br><a  href="#">更多..</a></center>');
  additem('精品赏析','<center><a  href="#">设计精品</a></center>');

  document.write('</span>')
  document.all.itemslayer.style.height=itemno*titleheight+contentheight;

  toitemindex=itemno-1;onitemindex=itemno-1;

  function  changeitem(clickitemindex){
      toitemindex=clickitemindex;
      if(toitemindex-onitemindex>0)  moveup();  else  movedown();
      runtimes++;
      if(runtimes>=stepno){
          onitemindex=toitemindex;
          runtimes=0;}
      else
          settimeout("changeitem(toitemindex)",10);
  }

  function  moveup(){
      for(i=onitemindex+1;i<=toitemindex;i++)
          eval('document.all.item'+i+'.style.top=parseint(document.all.item'+i+'.style.top)-contentheight/stepno;');
  }

  function  movedown(){
      for(i=onitemindex;i>toitemindex;i--)
          eval('document.all.item'+i+'.style.top=parseint(document.all.item'+i+'.style.top)+contentheight/stepno;');
  }
  changeitem(0);
//-->
</script>
</body>

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网