经典的菜单问题!help me! 高分报答
<!---------------------------------------------源代码--------------------------------------------------------------->
<style>
<!--
td{font-size:12px}
//-->
</style>
<TABLE width=778 border=0>
<TR>
<TD>
<TABLE border=1 cellspacing=0 bgColor=#ffffff width=100% bordercolordark=#ffffff>
<TR height=20>
<TD width=25% onmouseover="openMenu(0,150)" onmouseout="closeMenu()" bgColor=#FFCCCC> menu1</TD>
<TD width=25% onmouseover="openMenu(1,150)" onmouseout="closeMenu()" bgColor=#99CC66> menu2</TD>
<TD width=25% onmouseover="openMenu(2,150)" onmouseout="closeMenu()" bgColor=#66CC33> menu3</TD>
<TD width=25% onmouseover="openMenu(1,150)" onmouseout="closeMenu()" bgColor=#CC6600> menu4</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<select name=tadfs style="width:100%">
<option>a
<option>b
<option>c
</select>
<SCRIPT LANGUAGE="JavaScript">
<!--
//参数
var menuBgColor = "#CCCC66"; //菜单背景颜色
var menuBorderColor = "#000000"; //菜单边框的颜色
var menuLineH = 22; //菜单中每个栏目的高度
var menuItemBorderColor = "#000000";//菜单每个子栏目的边框颜色
var menuItemBgColor = "#CC9900";//菜单每个子栏目的背景颜色
//菜单栏目内容
var menuItem = new Array();
menuItem[0] = new Array();
menuItem[0][0] = ["笨猪one","test/one.html"];
menuItem[0][1] = ["笨猪two","testt.htm"];
menuItem[0][2] = ["笨猪3","testt.htm"];
menuItem[0][3] = ["笨猪4","testt.htm"];
menuItem[0][4] = ["笨猪5","testt.htm"];
menuItem[0][5] = ["笨猪笨猪笨猪笨猪","testt.htm"];
menuItem[0][6] = ["笨猪笨猪笨猪笨猪","testt.htm"];
menuItem[1] = new Array();
menuItem[1][0] = ["笨猪one","test/one.html"];
menuItem[1][1] = ["笨猪two","testt.htm"];
menuItem[1][2] = ["笨猪3","testt.htm"];
menuItem[1][3] = ["笨猪4","testt.htm"];
menuItem[2] = new Array();
menuItem[2][0] = ["笨猪one","test/one.html"];
menuItem[2][1] = ["笨猪two","testt.htm"];
var divId = "xxxxxxxMenu";
var frmName = "xxxxxxxMenuFrm";
document.write("<div id="+divId+" style='position: absolute;border:0;display:none; z-index: 999;' onmouseout=\"this.style.display='none'\" >");
// onmouseover=\"this.style.display=''\"
document.write("<iframe name="+frmName+" scrolling=no frameborder=0 width=100% height=100%></iframe></div>");
var menuDiv = document.getElementById(divId);
var menuFrm = document.frames(frmName);
function openMenu(key,w)
{
menuDiv.style.width = w;
var h = menuItem[key].length*menuLineH+4;
menuDiv.style.height = h;
menuFrm.resizeTo(w,h); //ie6下必须,ie5不必
var menuTbl = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=gb2312'></head>"
+"<body scroll=no bgColor="+menuBgColor+" style='margin:0' topmargin=0 bottommargin=0 style='border:solid 1px "+menuBorderColor+"'>"
+"<table border=0 cellspacing=0 cellpadding=0 width=97% align=center>";
for(var n=0;n<menuItem[key].length;n++){
menuTbl += "<tr height="+menuLineH+">"
+"<td style='font-size:13px;cursor:hand' onmouseover=\"this.bgColor='"+menuItemBgColor+"';this.style.border='solid 1px "+menuItemBorderColor+"'\" onmouseout=\"this.bgColor='';this.style.border='solid 0'\" onclick=\"parent.location='"+menuItem[key][n][1]+"'\">"
+menuItem[key][n][0]
+"</td>"
+"</tr>";
}
menuTbl += "<table></body></html>";
with(menuFrm){
document.writeln(menuTbl);
document.close();
}
var src = window.event.srcElement;
var oTop = src.offsetTop, cHeight = src.clientHeight, oLeft = src.offsetLeft;
while(src = src.offsetParent){
oTop += src.offsetTop; oLeft += src.offsetLeft;
}
menuDiv.style.top = oTop + cHeight;
menuDiv.style.left = oLeft;
menuDiv.style.display = "";
}
function closeMenu()
{
// menuDiv.style.display = "none";
}
//-->
</SCRIPT>
<!-------------------------------------------------------------------------------------------
存在问题如下:
1. ie5下面,当鼠标离开菜单的时候,菜单不能消失。ie6下面正常。问题可能在iframe屏蔽了前面的div
2. 找到menuFrm.resizeTo(w,h),为什么ie6下面不执行这行,div的显示高度就不能低于100左右
3. 本想做到当鼠标离开某个td时,下面的菜单就消失,但这样会导致在ie5下面从td移动到下方菜单上时,菜单就会消失,如何解决?
-------------------------------------------------------------------------------------------->