怎样做一个二级菜单?

hl2004 2006-04-25 01:57:24
怎样做一个二级菜单,急,在线等
...全文
123 4 点赞 打赏 收藏 举报
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
hl2004 2006-05-12
谢谢!!
  • 打赏
  • 举报
回复
gengjindong 2006-04-29
if (!window.activeMenus) window.activeMenus = new Array();
}
function addMenuItem(label, action) {
this.items[this.items.length] = label;
this.actions[this.actions.length] = action;
}
function FIND(item) {
if( window.mmIsOpera ) return(document.getElementById(item));
if (document.all) return(document.all[item]);
if (document.getElementById) return(document.getElementById(item));
return(false);
}
function writeMenus(container) {
if (window.triedToWriteMenus) return;
var agt = navigator.userAgent.toLowerCase();
window.mmIsOpera = agt.indexOf("opera") != -1;
if (!container && document.layers) {
window.delayWriteMenus = this.writeMenus;
var timer = setTimeout('delayWriteMenus()', 500);
container = new Layer(100);
clearTimeout(timer);
} else if (document.all || document.hasChildNodes || window.mmIsOpera) {
document.writeln('<span id="menuContainer"></span>');
container = FIND("menuContainer");
}
window.mmHideMenuTimer = null;
if (!container) return;
window.triedToWriteMenus = true;
container.isContainer = true;
container.menus = new Array();
for (var i=0; i<window.menus.length; i++)
container.menus[i] = window.menus[i];
window.menus.length = 0;
var countMenus = 0;
var countItems = 0;
var top = 0;
var content = '';
var lrs = false;
var theStat = "";
var tsc = 0;
if (document.layers) lrs = true;
for (var i=0; i<container.menus.length; i++, countMenus++) {
var menu = container.menus[i];
if (menu.bgImageUp || !menu.menuBgOpaque) {
menu.menuBorder = 0;
menu.menuItemBorder = 0;
}
if (lrs) {
var menuLayer = new Layer(100, container);
var lite = new Layer(100, menuLayer);
lite.top = menu.menuBorder;
lite.left = menu.menuBorder;
var body = new Layer(100, lite);
body.top = menu.menuBorder;
body.left = menu.menuBorder;
} else {
content += ''+
'<div id="menuLayer'+ countMenus +'" style="position:absolute;z-index:1;left:10px;top:'+ (i * 100) +'px;visibility:hidden;color:' + menu.menuBorderBgColor + ';">\n'+
' <div id="menuLite'+ countMenus +'" style="position:absolute;z-index:1;left:'+ menu.menuBorder +'px;top:'+ menu.menuBorder +'px;visibility:hide;" onmouseout="mouseoutMenu();">\n'+
' <div id="menuFg'+ countMenus +'" style="position:absolute;left:'+ menu.menuBorder +'px;top:'+ menu.menuBorder +'px;visibility:hide;">\n'+
'';
}
var x=i;
for (var i=0; i<menu.items.length; i++) {
var item = menu.items[i];
var childMenu = false;
var defaultHeight = menu.fontSize+2*menu.menuItemPadding;
if (item.label) {
item = item.label;
childMenu = true;
}
menu.menuItemHeight = menu.menuItemHeight || defaultHeight;
var itemProps = '';
if( menu.fontFamily != '' ) itemProps += 'font-family:' + menu.fontFamily +';';
itemProps += 'font-weight:' + menu.fontWeight + ';fontSize:' + menu.fontSize + 'px;';
if (menu.fontStyle) itemProps += 'font-style:' + menu.fontStyle + ';';
if (document.all || window.mmIsOpera)
itemProps += 'font-size:' + menu.fontSize + 'px;" onmouseover="onMenuItemOver(null,this);" onclick="onMenuItemAction(null,this);';
else if (!document.layers) {
itemProps += 'font-size:' + menu.fontSize + 'px;';
}
var l;
if (lrs) {
var lw = menu.menuWidth;
if( menu.menuItemHAlign == 'right' ) lw -= menu.menuItemPadding;
l = new Layer(lw,body);
}
var itemLeft = 0;
var itemTop = i*menu.menuItemHeight;
if( !menu.vertical ) {
itemLeft = i*menu.menuWidth;
itemTop = 0;
}
var dTag = '<div id="menuItem'+ countItems +'" style="position:absolute;left:' + itemLeft + 'px;top:'+ itemTop +'px;'+ itemProps +'">';
var dClose = '</div>'
if (menu.bgImageUp) dTag = '<div id="menuItem'+ countItems +'" style="background:url('+menu.bgImageUp+');position:absolute;left:' + itemLeft + 'px;top:'+ itemTop +'px;'+ itemProps +'">';
var left = 0, top = 0, right = 0, bottom = 0;
left = 1 + menu.menuItemPadding + menu.menuItemIndent;
right = left + menu.menuWidth - 2*menu.menuItemPadding - menu.menuItemIndent;
if( menu.menuItemVAlign == 'top' ) top = menu.menuItemPadding;
if( menu.menuItemVAlign == 'bottom' ) top = menu.menuItemHeight-menu.fontSize-1-menu.menuItemPadding;
if( menu.menuItemVAlign == 'middle' ) top = ((menu.menuItemHeight/2)-(menu.fontSize/2)-1);
bottom = menu.menuItemHeight - 2*menu.menuItemPadding;
var textProps = 'position:absolute;left:' + left + 'px;top:' + top + 'px;';
if (lrs) {
textProps +=itemProps + 'right:' + right + ';bottom:' + bottom + ';';
dTag = "";
dClose = "";
}
if(document.all && !window.mmIsOpera) {
item = '<div align="' + menu.menuItemHAlign + '">' + item + '</div>';
} else if (lrs) {
item = '<div style="text-align:' + menu.menuItemHAlign + ';">' + item + '</div>';
} else {
var hitem = null;
if( menu.menuItemHAlign != 'left' ) {
if(window.mmIsOpera) {
var operaWidth = menu.menuItemHAlign == 'center' ? -(menu.menuWidth-2*menu.menuItemPadding) : (menu.menuWidth-6*menu.menuItemPadding);
hitem = '<div id="menuItemHilite' + countItems + 'Shim" style="position:absolute;top:1px;left:' + menu.menuItemPadding + 'px;width:' + operaWidth + 'px;text-align:'
+ menu.menuItemHAlign + ';visibility:visible;">' + item + '</div>';
item = '<div id="menuItemText' + countItems + 'Shim" style="position:absolute;top:1px;left:' + menu.menuItemPadding + 'px;width:' + operaWidth + 'px;text-align:'
+ menu.menuItemHAlign + ';visibility:visible;">' + item + '</div>';
} else {
hitem = '<div id="menuItemHilite' + countItems + 'Shim" style="position:absolute;top:1px;left:1px;right:-' + (left+menu.menuWidth-3*menu.menuItemPadding) + 'px;text-align:'
+ menu.menuItemHAlign + ';visibility:visible;">' + item + '</div>';
item = '<div id="menuItemText' + countItems + 'Shim" style="position:absolute;top:1px;left:1px;right:-' + (left+menu.menuWidth-3*menu.menuItemPadding) + 'px;text-align:'
+ menu.menuItemHAlign + ';visibility:visible;">' + item + '</div>';
}
} else hitem = null;
}
if(document.all && !window.mmIsOpera) item = '<div id="menuItemShim' + countItems + '" style="position:absolute;left:0px;top:0px;">' + item + '</div>';
var dText = '<div id="menuItemText'+ countItems +'" style="' + textProps + 'color:'+ menu.fontColor +';">'+ item +' </div>\n'
+ '<div id="menuItemHilite'+ countItems +'" style="' + textProps + 'color:'+ menu.fontColorHilite +';visibility:hidden;">'
+ (hitem||item) +' </div>';
if (childMenu) content += ( dTag + dText + '<div id="childMenu'+ countItems +'" style="position:absolute;left:0px;top:3px;"><img src="'+ menu.childMenuIcon +'"></div>\n' + dClose);
else content += ( dTag + dText + dClose);
if (lrs) {
  • 打赏
  • 举报
回复
gengjindong 2006-04-29
首先做首要页面,先准备一些图片,做一个图片交换的菜单栏
然后在与之间插入以下两个JS文件
<script language="JavaScript" src="images/js/menu.js"></script> //menu.js代码附后
<script language="JavaScript" src="images/js/mm_menu.js"></script> //mm_menu.js代码附后
最后在后面body后加入如下代码:
<script language="JavaScript1.2">mmLoadMenus();</script>
//以下代码为menu.js内具体代码!
// JavaScript Document
<!--变量client_true用于判断是否存在菜单,writeMenus();是用于驱动菜单的
function mmLoadMenus() {
var client_true;
client_true = "";
window.menu_1 = new Menu("root",72,26,"",12,"#000000","#FFFFFF","#5DAFFD","#000080","left","middle",0,0,100,-5,7,true,true,true,3,false,false);
client_true =menu_1;
menu_1.addMenuItem("公司简况","location='interGroup1.asp?dir_id=63'");
client_true =menu_1;
menu_1.addMenuItem("董事长致词","location='interGroup1.asp?dir_id=62'");
client_true =menu_1;
menu_1.addMenuItem("总经理寄语","location='interGroup1.asp?dir_id=61'");
client_true =menu_1;
menu_1.addMenuItem("公司架构","location='interGroup1.asp?dir_id=13'");
menu_1.hideOnMouseOut=true;
menu_1.bgColor='#D0DDFF';
menu_1.menuBorder=1;
menu_1.menuLiteBgColor='#D0DDFF';
menu_1.menuBorderBgColor='#000066';
window.menu_4 = new Menu("root",72,26,"",12,"#000000","#FFFFFF","#5DAFFD","#000080","left","middle",0,0,100,-5,7,true,true,true,3,false,false);
client_true =menu_4;
menu_4.addMenuItem("业务介绍","location='interGroup4.asp?dir_id=64'");
client_true =menu_4;
menu_4.addMenuItem("资产推荐","location='interGroup4.asp?dir_id=65'");
client_true =menu_4;
menu_4.addMenuItem("资产处置","location='interGroup4.asp?dir_id=66'");
menu_4.hideOnMouseOut=true;
menu_4.bgColor='#D0DDFF';
menu_4.menuBorder=1;
menu_4.menuLiteBgColor='#D0DDFF';
menu_4.menuBorderBgColor='#000066';
window.menu_7 = new Menu("root",72,26,"",12,"#000000","#FFFFFF","#5DAFFD","#000080","left","middle",0,0,100,-5,7,true,true,true,3,false,false);
client_true =menu_7;
menu_7.addMenuItem("公司大事记","location='interGroup7.asp?dir_id=73'");
client_true =menu_7;
menu_7.addMenuItem("企业文化","location='interGroup7.asp?dir_id=72'");
menu_7.hideOnMouseOut=true;
menu_7.bgColor='#D0DDFF';
menu_7.menuBorder=1;
menu_7.menuLiteBgColor='#D0DDFF';
menu_7.menuBorderBgColor='#000066';
window.menu_8 = new Menu("root",72,26,"",12,"#000000","#FFFFFF","#5DAFFD","#000080","left","middle",0,0,100,-5,7,true,true,true,3,false,false);
client_true =menu_8;
menu_8.addMenuItem("人才战略","location='interGroup8.asp?dir_id=64'");
client_true =menu_8;
menu_8.addMenuItem("现缺网位","location='interGroup8_1.asp?dir_id=65'");
client_true =menu_8;
menu_8.addMenuItem("毛遂自荐","location='interGroup8_2.asp?dir_id=66'");
menu_8.hideOnMouseOut=true;
menu_8.bgColor='#D0DDFF';
menu_8.menuBorder=1;
menu_8.menuLiteBgColor='#D0DDFF';
menu_8.menuBorderBgColor='#000066';
client_true.writeMenus();
}
//-->
//以下代码为mm_menu.js 内具体代码!
/**
* mm_menu 20MAR2002 Version 6.0
* Andy Finnell, March 2002
* Copyright (c) 2000-2002 Macromedia, Inc.
*
* based on menu.js
* by gary smith, July 1997
* Copyright (c) 1997-1999 Netscape Communications Corp.
*
* Netscape grants you a royalty free license to use or modify this
* software provided that this copyright notice appears on all copies.
* This software is provided "AS IS," without a warranty of any kind.
*/
function Menu(label, mw, mh, fnt, fs, fclr, fhclr, bg, bgh, halgn, valgn, pad, space, to, sx, sy, srel, opq, vert, idt, aw, ah)
{
this.version = "020320 [Menu; mm_menu.js]";
this.type = "Menu";
this.menuWidth = mw;
this.menuItemHeight = mh;
this.fontSize = fs;
this.fontWeight = "plain";
this.fontFamily = fnt;
this.fontColor = fclr;
this.fontColorHilite = fhclr;
this.bgColor = "#555555";
this.menuBorder = 1;
this.menuBgOpaque=opq;
this.menuItemBorder = 1;
this.menuItemIndent = idt;
this.menuItemBgColor = bg;
this.menuItemVAlign = valgn;
this.menuItemHAlign = halgn;
this.menuItemPadding = pad;
this.menuItemSpacing = space;
this.menuLiteBgColor = "#ffffff";
this.menuBorderBgColor = "#777777";
this.menuHiliteBgColor = bgh;
this.menuContainerBgColor = "#cccccc";
this.childMenuIcon = "arrows.gif";
this.submenuXOffset = sx;
this.submenuYOffset = sy;
this.submenuRelativeToItem = srel;
this.vertical = vert;
this.items = new Array();
this.actions = new Array();
this.childMenus = new Array();
this.hideOnMouseOut = true;
this.hideTimeout = to;
this.addMenuItem = addMenuItem;
this.writeMenus = writeMenus;
this.MM_showMenu = MM_showMenu;
this.onMenuItemOver = onMenuItemOver;
this.onMenuItemAction = onMenuItemAction;
this.hideMenu = hideMenu;
this.hideChildMenu = hideChildMenu;
if (!window.menus) window.menus = new Array();
this.label = " " + label;
window.menus[this.label] = this;
window.menus[window.menus.length] = this;
  • 打赏
  • 举报
回复
gengjindong 2006-04-25
用CSS嘛,还有DW中也有这样的FLASH按扭。也是二级菜单。
自己可以去加上看看。
  • 打赏
  • 举报
回复
相关推荐
发帖
ASP
加入

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2006-04-25 01:57
社区公告
暂无公告