如何隐藏菜单项?

kmajian 2010-01-27 09:01:55
有两个菜单网页,一个是一级菜单,一个是二级菜单。

一级菜单的代码如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>T&W Wireless Router</title>
<link href="style01.css" rel="stylesheet" type="text/css">
<script language="javascript" src="forbidView.js"></script>
<body>

<div class="top">
<div class="logo"></div>
</div>
<div class="menu01">
<ul>
<li id="css1"><a href="left_status.asp" target="Left" onclick="parent.Main.location.href='summary.asp'; parent.Right.location.href='help_dev_info.asp'" hidefocus="true">Status</a></li>
<li id="css2"><a href="left_network.asp" target="Left" onclick="parent.Main.location.href='wan.asp'; parent.Right.location.href='help_wan_setup.asp'" hidefocus="true">Network</a></li>
<li id="css3"><a href="left_wireless.asp" target="Left" onclick="parent.Main.location.href='ssid.asp'; parent.Right.location.href='help_ssid_setting.asp'" hidefocus="true">Wireless</a></li>
<li id="css4"><a href="left_security.asp" target="Left" onclick="parent.Main.location.href='firewall.asp'; parent.Right.location.href='help_firewall_setting.asp'" hidefocus="true">Security</a></li>
<li id="css5"><a href="left_application.asp" target="Left" onclick="parent.Main.location.href='router_mode.asp'; parent.Right.location.href='help_router_mode.asp'" hidefocus="true">Application</a></li>
<li id="css6"><a href="left_management.asp" target="Left" onclick="parent.Main.location.href='user.asp'; parent.Right.location.href='help_user_mngr.asp'" hidefocus="true">Management</a></li>
<li id="css7"><a href="logout.asp" target="Main" hidefocus="true">Logout</a></li>
</ul>
</div>
</body>


二级菜单的代码如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>TW</title>
<link href="style01.css" rel="stylesheet" type="text/css">
<script language="javascript" src="forbidView.js"></script>
</head>

<body>
<div class="kuangLeft">
<ul id="nav">
<li><span><a href="#Menu=ChildMenu1" onClick="DoMenu('ChildMenu1')" hidefocus="true">WAN Setting</a></span>
<ul id="ChildMenu1" class="collapsed">
<li><span ><a href="wan.asp" target="Main" onClick="parent.Right.location.href='help_wan_setup.asp'" hidefocus="true">  WAN</a></span ></li>
</ul>
</li>
<li><span><a href="#Menu=ChildMenu2" onClick="DoMenu('ChildMenu2')" hidefocus="true">LAN Setting</a></span>
<ul id="ChildMenu2" class="collapsed">
<li><span ><a href="lan.asp" target="Main" onClick="parent.Right.location.href='help_lan_setup.asp'" hidefocus="true">  LAN</a></span ></li>
</ul>
</li>
<li><span><a href="#Menu=ChildMenu3" onClick="DoMenu('ChildMenu3')" hidefocus="true">Time Management</a></span>
<ul id="ChildMenu3" class="collapsed">
<li><span ><a href="ntp.asp" target="Main" onClick="parent.Right.location.href='help_ntp_srv.asp'" hidefocus="true">  Time & NTP Server</a></span ></li>
</ul>
</li>
<li><span><a href="#Menu=ChildMenu4" onClick="DoMenu('ChildMenu4')" hidefocus="true">Static-route Setting</a></span>
<ul id="ChildMenu4" class="collapsed">
<li><span ><a href="lan_static_route.asp" target="Main" onClick="parent.Right.location.href='help_lan_route.asp'" hidefocus="true">  LAN Static-route</a></span ></li>
<li><span ><a href="wan_static_route.asp" target="Main" onClick="parent.Right.location.href='help_wan_route.asp'" hidefocus="true">  WAN Static-route</a></span ></li>
</ul>
</li>
</ul>
</div>

</body>
</html>
<script type=text/javascript><!--
var LastLeftID = "";

function menuFix() {
var obj = document.getElementById("nav").getElementsByTagName("li");

for (var i=0; i<obj.length; i++) {
obj[i].onmouseover=function() {
this.className+=(this.className.length>0? " ": "") + "sfhover";
}
obj[i].onMouseDown=function() {
this.className+=(this.className.length>0? " ": "") + "sfhover";
}
obj[i].onMouseUp=function() {
this.className+=(this.className.length>0? " ": "") + "sfhover";
}
obj[i].onmouseout=function() {
this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
}
}
}

function DoMenu(emid)
{
var obj = document.getElementById(emid);
obj.className = (obj.className.toLowerCase() == "expanded"?"collapsed":"expanded");
if((LastLeftID!="")&&(emid!=LastLeftID)) //关闭上一个Menu
{
document.getElementById(LastLeftID).className = "collapsed";
}
LastLeftID = emid;
}

function GetMenuID()
{

var MenuID="";
var _paramStr = new String(window.location.href);

var _sharpPos = _paramStr.indexOf("#");

if (_sharpPos >= 0 && _sharpPos < _paramStr.length - 1)
{
_paramStr = _paramStr.substring(_sharpPos + 1, _paramStr.length);
}
else
{
_paramStr = "";
}

if (_paramStr.length > 0)
{
var _paramArr = _paramStr.split("&");
if (_paramArr.length>0)
{
var _paramKeyVal = _paramArr[0].split("=");
if (_paramKeyVal.length>0)
{
MenuID = _paramKeyVal[1];
}
}
/*
if (_paramArr.length>0)
{
var _arr = new Array(_paramArr.length);
}

//取所有#后面的,菜单只需用到Menu
//for (var i = 0; i < _paramArr.length; i++)
{
var _paramKeyVal = _paramArr[i].split('=');

if (_paramKeyVal.length>0)
{
_arr[_paramKeyVal[0]] = _paramKeyVal[1];
}
}
*/
}

if(MenuID!="")
{
DoMenu(MenuID)
}
}

GetMenuID(); //*这两个function的顺序要注意一下,不然在Firefox里GetMenuID()不起效果
menuFix();
--></script>



在一级菜单中我要隐藏‘Network’和‘Security’这两项。在二级菜单中要隐藏'WAN Setting'、‘Time Management’、‘Static-route Setting’这几项。请问用JavaScript怎么动态控制隐藏或者显示这些菜单项呢? 谢谢!
...全文
232 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
浴火_凤凰 2010-01-28
  • 打赏
  • 举报
回复
1楼的可以试一试
passself 2010-01-27
  • 打赏
  • 举报
回复
对一样的操作,设置相同的class,设置奇偶事件点击打开,点击隐藏就可以了
zhenxianxian 2010-01-27
  • 打赏
  • 举报
回复
style.display="block"和"none"\

block为显示 ,none为不显示 。 自己上网查查display属性怎么使用就懂了
EXIT_ON_CLOSE 2010-01-27
  • 打赏
  • 举报
回复
路过
kmajian 2010-01-27
  • 打赏
  • 举报
回复
不太明白楼上的意思。能给出实现的JS代码吗? 谢谢!

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧