手机挂绳:有JS高手进!关于JS菜单!

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/03 09:52:04
我想做一个切换菜单!虽然实现了!效果如下!
但代码太过窿于,只写了5条就这多了!我最后要写十几条那不多死了啊!
请教各位老大,如何优化此脚本啊?!谢谢了!

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<SCRIPT language=JavaScript>
function toggle1()
{
if (w1.style.display=="none")
{w1.style.display=""
w2.style.display="none"
w3.style.display="none"
w4.style.display="none"
w5.style.display="none"
}
else
{w1.style.display="none"}
}

function toggle2()
{
if (w2.style.display=="none")
{w2.style.display=""
w1.style.display="none"
w3.style.display="none"
w4.style.display="none"
w5.style.display="none"
}
else
{w2.style.display="none"}
}

function toggle3()
{
if (w3.style.display=="none")
{w3.style.display=""
w1.style.display="none"
w2.style.display="none"
w4.style.display="none"
w5.style.display="none"
}
else
{w3.style.display="none"}
}

function toggle4()
{
if (w4.style.display=="none")
{w4.style.display=""
w1.style.display="none"
w3.style.display="none"
w2.style.display="none"
w5.style.display="none"
}
else
{w4.style.display="none"}
}
function toggle5()
{
if (w5.style.display=="none")
{w5.style.display=""
w1.style.display="none"
w3.style.display="none"
w2.style.display="none"
w4.style.display="none"
}
else
{w5.style.display="none"}
}
</SCRIPT>

<body>
<table width="405" height="279" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="30" align="center" valign="middle" bgcolor="#CC0066"><a href="#" onClick="toggle1();" >■</a></td>
<td align="center" valign="middle" bgcolor="#00FFFF"><a href="#" onClick="toggle2();" >■</a></td>
<td align="center" valign="middle" bgcolor="#CC6699"><a href="#" onClick="toggle3();" >■</a></td>
<td align="center" valign="middle" bgcolor="#0066FF"><a href="#" onClick="toggle4();" >■</a></td>
<td align="center" valign="middle" bgcolor="#FFCC00"><a href="#" onClick="toggle5();" >■</a></td>
</tr>
<tr id="w1">
<td height="30" colspan="5" bgcolor="#CC0066"> </td>
</tr>
<tr id="w2" style="display:none;">
<td height="30" colspan="5" bgcolor="#00FFFF"> </td>
</tr>
<tr id="w3" style="display:none;">
<td height="30" colspan="5" bgcolor="#CC6699"> </td>
</tr>
<tr id="w4" style="display:none;">
<td height="30" colspan="5" bgcolor="#0066FF"> </td>
</tr>
<tr id="w5" style="display:none;">
<td height="30" colspan="5" bgcolor="#FFCC00"> </td>
</tr>
</table>
</body>
</html>
昨天晚上贴了一次!不知道为什么分给我扣了!却不给我把问题贴出来?难道它只吃分吗??晕!白扣了我20分!先放10分算了!给出正解的答案再追10分!免得又给我吃了!