:( 想弄这个菜单,但是有个问题,就是这个子菜单是透明的..二级,三级菜单都是个透明背景.我希望的是能够填充一种颜色去..望知道怎么修改的帮帮手..下面是源码,附件也是这个的源码.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>菜单</title>
</head>
<body>
<script language="JavaScript">
//----------------------菜单属性设置--------------------------
var MHeight = 20; //菜单高度
var MWidth = 80; //菜单宽度
var MColor = "#000000";//菜单颜色
var MFColor = "#000000"; //字体颜色
var MOverBG = "#333333"; //鼠标经过时的背景颜色
var MOverFC = "#ffffff"; //鼠标经过时的字体颜色
var menuSpeed = 50; //---------- 菜单显示速度 ------------//
var alphaStep = 30; //---------- Alpaha 变化 度 -----------//
var str;
/*--------------创建菜单对象----------*/
var oldTR = null; //控制鼠标经过时背景颜色变量
var SubMenuList = new Array;
var NowSubMenu ="";
var M = 0, MN;
function Menu(objName)
{
this.name = objName;
this.addMenu = addMenu;
document.write("<table id="+objName+" cellpadding=0 cellspacing=0 style='position:absolute;left:0;top:0;border:1px solid "+MColor+";font-size:12px;visibility:hidden;filter:Alpha(Opacity=100);'></table>");
this.length = 0;
}
function addMenu(Word,Link,MChild)
{
var row,cell;
var oBody = document.getElementById(this.name);
var tbody = oBody.childNodes[0];
oBody.appendChild(tbody);
row = document.createElement("TR");
tbody.appendChild(row);
row.id = this.name+"_"+this.length;
row.attachEvent("onmouseover",MOver(row,MChild)); //菜单变色
row.attachEvent("onclick",MClick(row));
row.style.cursor = "hand";
for(i=0;i<4;i++)
{
cell = document.createElement("TD");
row.appendChild(cell);
}
with(row)
{
cells(0).style.backgroundColor = MColor;
cells(0).style.pixelWidth = "4";
cells(1).style.pixelHeight = MHeight;
cells(1).style.pixelWidth = MWidth;
cells(1).style.textAlign = "left";
cells(1).innerHTML = "<a href="+Link+"></a>"+Word;
if(MChild)
cells(2).innerHTML = "<img src=arrows.gif>";
else
cells(2).innerHTML = " ";
cells(3).innerText = " ";
}
this.length++;
}
function MClick(obj)
{
return mc;
function mc()
{
if(obj.cells(1).all.tags("A").length>0)
{
obj.cells(1).all.tags("A")(0).click();
}
}
}
function MOver(obj,isShow)
{
return mo;
function mo()
{
if(isShow)
ShowMenu(isShow,0,obj);
else
{
NowSubMenu=obj.parentElement.parentElement.id;
HideMenu(1);
}
if(oldTR)
with(eval(oldTR).style)
{
backgroundColor = "";
color = MFColor;
}
obj.style.backgroundColor = MOverBG;
obj.style.color = MOverFC;
oldTR = obj.id;
}
}
function ShowMenu(Menu,isTop,OldMenu)
{
if(isTop)
{ M = 1;
MN = Menu;
NowSubMenu = "";
HideMenu(1);
SubMenuList[0] = Menu;
var Menu = document.getElementById(Menu);
var EventObj = event.srcElement;
var ET = EventObj.offsetTop, EH = EventObj.offsetHeight, EL = EventObj.offsetLeft;
var BH = document.body.clientHeight, BT = document.body.scrollTop;
while(EventObj=EventObj.offsetParent){ET += EventObj.offsetTop;EL += EventObj.offsetLeft;}
/*window.status="ET:="+ET+"EH:="+EH+"EL:="+EL
+ "BH="+BH+"BT="+BT;*/
if(BH+BT-ET-EH>=Menu.offsetHeight)
Menu.style.pixelTop = ET+EH;
else
Menu.style.pixelTop = (ET-BT>=Menu.offsetHeight)? ET-Menu.offsetHeight : BT;
Menu.style.pixelLeft = EL;
Menu.style.visibility = "visible";
alphaing = setInterval("ShowAlpha('"+Menu.id+"',"+alphaStep+")",menuSpeed);
}
else
{
var Menu = document.getElementById(Menu);
var topobj = OldMenu.parentElement.parentElement;
NowSubMenu = topobj.id;
HideMenu(1);
if(MN!=NowSubMenu){M++;MN=NowSubMenu;}
SubMenuList[M]=Menu.id;
var ET = topobj.offsetTop, EH = topobj.offsetHeight, EL = topobj.offsetLeft, EW = topobj.offsetWidth;
var BH = document.body.clientHeight, BT = document.body.scrollTop ,BW=document.body.clientWidth;
while(topobj=topobj.offsetParent){ET += topobj.offsetTop;EL += topobj.offsetLeft;}
if(BH+BT-ET-OldMenu.offsetTop>=Menu.offsetHeight)
Menu.style.pixelTop = ET + OldMenu.offsetTop;
else
Menu.style.pixelTop = (ET+OldMenu.offsetTop+OldMenu.offsetHeight >=Menu.offsetHeight)? ET+OldMenu.offsetTop+OldMenu.offsetHeight-Menu.offsetHeight :BT;
if(BW-EL-EW>=Menu.offsetWidth)
Menu.style.pixelLeft = EL + EW;
else
Menu.style.pixelLeft = (BW>=Menu.offsetWidth)?EL-Menu.offsetWidth:0;
Menu.style.visibility = "visible";
if(Menu.alphaing)clearInterval(Menu.alphaing);
Menu.alphaing = setInterval("ShowAlpha('"+Menu.id+"',"+alphaStep+")",menuSpeed);
}
}
function HideMenu(num)
{
var themenu="";
if (num==1) themenu=NowSubMenu;
for(var i=SubMenuList.length-1;i>=0;i--)
{
if(SubMenuList[i]&&SubMenuList[i]!=themenu)
{
// document.getElementById(SubMenuList[i]).alphaing = setInterval("HideAlpha('"+SubMenuList[i]+"',"+alphaStep+")",menuSpeed);
document.getElementById(SubMenuList[i]).style.visibility ="hidden";
document.getElementById(SubMenuList[i]).filters.Alpha.Opacity =100;
SubMenuList[i] = null;
}
else
if (SubMenuList[i]==NowSubMenu)return;
}
NowSubMenu="";
}
function ShowAlpha(obj,num)
{
var obj = document.getElementById(obj);
if(obj.filters.Alpha.Opacity<100)
{ obj.filters.Alpha.Opacity += num;}
else
{
clearInterval(obj.alphaing);
obj.filters.Alpha.Opacity = 100;
obj.alphaing = false;
}
}
function document.onclick()
{HideMenu();}
</script>
<style type="text/css">
<!--
body {
background-color: #999999;
}
-->
</style></head>
<body >
<script>
var TM = new Menu("TM");
TM.addMenu("你好","http://www.baidu.com","TMC");
TM.addMenu("你好","http://www.baidu.com","TMC1");
TM.addMenu("你好","http://www.baidu.com");
TM.addMenu("你好","http://www.baidu.com");
TM.addMenu("你好","http://www.baidu.com");
TM.addMenu("你好","http://www.baidu.com");
var TMC1 = new Menu("TMC1");
TMC1.addMenu("你好","http://www.baidu.com");
TMC1.addMenu("你好","http://www.baidu.com");
TMC1.addMenu("你好","http://www.baidu.com");
var TMC = new Menu("TMC");
TMC.addMenu("你好","http://www.baidu.com");
TMC.addMenu("你好","http://www.baidu.com");
TMC.addMenu("你好","http://www.baidu.com");
TMC.addMenu("你好","http://www.baidu.com","TMCC");
var TMCC = new Menu("TMCC");
TMCC.addMenu("你好","http://www.baidu.com");
TMCC.addMenu("你好","http://www.baidu.com");
TMCC.addMenu("你好","http://www.baidu.com");
TMCC.addMenu("你好","http://www.baidu.com");
var TM3 = new Menu("TM3");
TM3.addMenu("你好","http://www.baidu.com");
TM3.addMenu("你好","http://www.baidu.com","TM4");
var TM4 = new Menu("TM4");
TM4.addMenu("你好","http://www.baidu.com");
TM4.addMenu("你好","http://www.baidu.com");
TM4.addMenu("你好","http://www.baidu.com","TM6");
TM4.addMenu("你好","http://www.baidu.com","TM5");
var TM5 = new Menu("TM5");
TM5.addMenu("你好","http://www.baidu.com");
TM5.addMenu("你好","http://www.baidu.com");
TM5.addMenu("你好","http://www.baidu.com");
TM5.addMenu("你好","http://www.baidu.com");
var TM6 = new Menu("TM6");
TM6.addMenu("你好","http://www.baidu.com");
TM6.addMenu("你好","http://www.baidu.com");
TM6.addMenu("你好","http://www.baidu.com");
TM6.addMenu("你好","http://www.baidu.com");
var TM = new Menu("TM7");
TM.addMenu("我也好","http://www.baidu.com");
TM.addMenu("我也好","http://www.baidu.com");
TM.addMenu("我也好","http://www.baidu.com");
TM.addMenu("我也好","http://www.baidu.com");
TM.addMenu("我也好","http://www.baidu.com");
</script>
<table width="768" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
<tr>
<td height="20" > <a href='javascrpt:;' onMouseOver="ShowMenu('TM',1)">菜单一</a></td>
<td> <a href='javascrpt:;' onMouseOver="ShowMenu('TM3',1)">菜单一</a></td>
<td><a href="#"onMouseOver="ShowMenu('TM4',1)">sfsfs</a></td>
<td><a href="#" onMouseOver="ShowMenu('TM3',1)">sfsfs</a></td>
<td><a href="#"onMouseOver="ShowMenu('TM4',1)">sfsfs</a></td>
<td><a href="#"onMouseOver="ShowMenu('TM4',1)">sfsfs</a></td>
<td><a href="#"onMouseOver="ShowMenu('TM4',1)">sfsfs</a></td>
<td><a href="#"onMouseOver="ShowMenu('TM4',1)">sfsfs</a></td>
</tr>
</table>
</body>
</html>
[此贴子已经被作者于2007-2-6 17:23:01编辑过]