下面是一段php的代码,是层叠显示的,现在我想在jsp中做,应该是在servlet中实现,但是老是不成功,请问有没有会的,谢谢!
<?php
@session_start();
$ROOT_PATH="../";include $ROOT_PATH."include/config.php";
include $ROOT_PATH."include/db.php";
include $ROOT_PATH."include/chkuser.php";
?>
<html>
<head>
<title> </title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
<meta http-equiv="expires" content="wed, 26 Feb 1997 08:21:57 GMT">
<link rel="stylesheet" href="../css/main.css" type="text/css"><script language="JavaScript">
var o=0;
function numcheck(form) { //v2.0
for(var i=0;i<form.elements.length;i++)
{
var e=form.elements[i];
if(e.checked)
o=o+1;
}
if (o==1){ parent.a3.disabled=false;
parent.a2.disabled=false;
parent.a1.disabled=false;
}
else if(o==0){
parent.a1.disabled=true;
parent.a2.disabled=true;
parent.a3.disabled=true;
}else{ parent.a1.disabled=true;
parent.a2.disabled=true;
parent.a3.disabled=false;
}
o=0;
}
</script><SCRIPT LANGUAGE="JavaScript">
<!--
function ShowMenu(MenuID)
{
if(MenuID.style.display=="none")
{
MenuID.style.display="";
}
else
{
MenuID.style.display="none";
}
} //-->
</SCRIPT></head>
<body bgcolor="#FFFFFF" text="#000000" style="margin:0">
<table width="100%" border="0" cellspacing="1" cellpadding="3" class="tablebg">
<tr>
<td class="tdbg2">
<form name="form1" method="post" action="">
<?php//基本变量设置
$GLOBALS["ID"] =1; //用来跟踪下拉菜单的ID号
$layer=2; //用来跟踪当前菜单的级数
//提取一级菜单
$sql="select * from web_branch where Pid=0"; $result=$mysql->sql_query($sql);//如果一级菜单存在则开始菜单的显示
if($mysql->sql_numrows($result)>0) ShowTreeMenu($mysql,$result,$layer,$ID); //ShowTreeMenu
function ShowTreeMenu($mysql,$result,$layer)
{
//取得需要显示的菜单的项目数
$numrows=$mysql->sql_numrows($result); //开始显示菜单,每个子菜单都用一个表格来表示
echo "<table cellpadding='0' cellspacing='0' border='0'>"; for($rows=0;$rows<$numrows;$rows++)
{
//将当前菜单项目的内容导入数组
$menu=$mysql->sql_fetchrow($result); //提取菜单项目的子菜单记录集
$sql="select * from web_branch where Pid=$menu[Id]";
$result_sub=$mysql->sql_query($sql); echo "<tr>";
//如果该菜单项目有子菜单,则添加JavaScript onClick语句
if($mysql->sql_numrows($result_sub)>0)
{
echo "<td width='40'><input type='checkbox' name='bra[]' value='$menu[Id]' onclick='numcheck(this.form)'><img src='../images/tree_folder.gif' border='0'></td>";
echo "<td style='CURSOR:hand' onClick='javascript:ShowMenu(Menu".$GLOBALS["ID"].");'>";
}
else
{
echo "<td width='40'><input type='checkbox' name='bra[]' value='$menu[Id]' onclick='numcheck(this.form)'><img src='../images/tree_file.gif' border='0'></td>";
echo "<td style='CURSOR:hand'>";
} echo "<a href='#' onclick=\"parent.right.location='branch_display.php?ID=$menu[Id]'\">$menu[Art]</a>";
echo "</td></tr>"; //如果该菜单项目有子菜单,则显示子菜单
if($mysql->sql_numrows($result_sub)>0)
{
//指定该子菜单的ID和style,以便和onClick语句相对应
echo "<tr id=Menu".$GLOBALS["ID"]++." style='display:show'>";
echo "<td width='20'> </td>";
echo "<td>";
//将级数加1
$layer++;
//递归调用ShowTreeMenu()函数,生成子菜单
ShowTreeMenu($mysql,$result_sub,$layer);
//子菜单处理完成,返回到递归的上一层,将级数减1
$layer--;
echo "</td></tr>";
}
//继续显示下一个菜单项目
}
echo "</table>";
}
?>
</form>
</td>
</tr>
</table>
</body>
</html>
<?php
@session_start();
$ROOT_PATH="../";include $ROOT_PATH."include/config.php";
include $ROOT_PATH."include/db.php";
include $ROOT_PATH."include/chkuser.php";
?>
<html>
<head>
<title> </title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
<meta http-equiv="expires" content="wed, 26 Feb 1997 08:21:57 GMT">
<link rel="stylesheet" href="../css/main.css" type="text/css"><script language="JavaScript">
var o=0;
function numcheck(form) { //v2.0
for(var i=0;i<form.elements.length;i++)
{
var e=form.elements[i];
if(e.checked)
o=o+1;
}
if (o==1){ parent.a3.disabled=false;
parent.a2.disabled=false;
parent.a1.disabled=false;
}
else if(o==0){
parent.a1.disabled=true;
parent.a2.disabled=true;
parent.a3.disabled=true;
}else{ parent.a1.disabled=true;
parent.a2.disabled=true;
parent.a3.disabled=false;
}
o=0;
}
</script><SCRIPT LANGUAGE="JavaScript">
<!--
function ShowMenu(MenuID)
{
if(MenuID.style.display=="none")
{
MenuID.style.display="";
}
else
{
MenuID.style.display="none";
}
} //-->
</SCRIPT></head>
<body bgcolor="#FFFFFF" text="#000000" style="margin:0">
<table width="100%" border="0" cellspacing="1" cellpadding="3" class="tablebg">
<tr>
<td class="tdbg2">
<form name="form1" method="post" action="">
<?php//基本变量设置
$GLOBALS["ID"] =1; //用来跟踪下拉菜单的ID号
$layer=2; //用来跟踪当前菜单的级数
//提取一级菜单
$sql="select * from web_branch where Pid=0"; $result=$mysql->sql_query($sql);//如果一级菜单存在则开始菜单的显示
if($mysql->sql_numrows($result)>0) ShowTreeMenu($mysql,$result,$layer,$ID); //ShowTreeMenu
function ShowTreeMenu($mysql,$result,$layer)
{
//取得需要显示的菜单的项目数
$numrows=$mysql->sql_numrows($result); //开始显示菜单,每个子菜单都用一个表格来表示
echo "<table cellpadding='0' cellspacing='0' border='0'>"; for($rows=0;$rows<$numrows;$rows++)
{
//将当前菜单项目的内容导入数组
$menu=$mysql->sql_fetchrow($result); //提取菜单项目的子菜单记录集
$sql="select * from web_branch where Pid=$menu[Id]";
$result_sub=$mysql->sql_query($sql); echo "<tr>";
//如果该菜单项目有子菜单,则添加JavaScript onClick语句
if($mysql->sql_numrows($result_sub)>0)
{
echo "<td width='40'><input type='checkbox' name='bra[]' value='$menu[Id]' onclick='numcheck(this.form)'><img src='../images/tree_folder.gif' border='0'></td>";
echo "<td style='CURSOR:hand' onClick='javascript:ShowMenu(Menu".$GLOBALS["ID"].");'>";
}
else
{
echo "<td width='40'><input type='checkbox' name='bra[]' value='$menu[Id]' onclick='numcheck(this.form)'><img src='../images/tree_file.gif' border='0'></td>";
echo "<td style='CURSOR:hand'>";
} echo "<a href='#' onclick=\"parent.right.location='branch_display.php?ID=$menu[Id]'\">$menu[Art]</a>";
echo "</td></tr>"; //如果该菜单项目有子菜单,则显示子菜单
if($mysql->sql_numrows($result_sub)>0)
{
//指定该子菜单的ID和style,以便和onClick语句相对应
echo "<tr id=Menu".$GLOBALS["ID"]++." style='display:show'>";
echo "<td width='20'> </td>";
echo "<td>";
//将级数加1
$layer++;
//递归调用ShowTreeMenu()函数,生成子菜单
ShowTreeMenu($mysql,$result_sub,$layer);
//子菜单处理完成,返回到递归的上一层,将级数减1
$layer--;
echo "</td></tr>";
}
//继续显示下一个菜单项目
}
echo "</table>";
}
?>
</form>
</td>
</tr>
</table>
</body>
</html>
楼主想要的是javascript Menu ?