分类出来了,但是点击下一类时,不显示
我想要的效果,点击大类显示小类,
比如3个小类
点第一小类,小类展开,
点第二个类,第一个小类和第三个小类收缩,第二个小类展开,点第三个小类,第一个和第二个小类收缩,怎样实现
<?php
$Conn=mysql_connect("localhost:3306","root","123456");
$db=mysql_select_db("empirecmd"); //打开数据库
mysql_query("SET NAMES 'gb2312'"); //避免乱码
$tpye=trim($_GET["tpye"]);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<LINK href="http://www.w-w365.com/skin/jr/css/css.css" type=text/css rel=stylesheet>
<head>
<script type="text/javascript">
var count=0;//做计数器
var limit=new Array();//用于记录当前显示的哪几个菜单
var countlimit=1;//同时打开菜单数目,可自定义
function ShowMenu(ID)
{
obj = eval("Menu" + ID);
if(obj.style.display=="none")
{
obj.style.display="block";
if (count<countlimit) {//限制2个
limit[count]=ID;//录入数组
count++;
}
else {
eval("Menu" + limit[0]).style.display = "none";
for (i=0;i<limit.length-1;i++) {limit[i]=limit[i+1];}//数组去掉头一位,后面的往前挪一位
limit[limit.length-1]=ID;
}
}
else
{
obj.style.display="none";
var j;
for (i=0;i<limit.length;i++) {if (limit[i]==ID) j=i;}//获取当前点击的菜单在limit数组中的位置
for (i=j;i<limit.length-1;i++) {limit[i]=limit[i+1];}//j以后的数组全部往前挪一位
limit[limit.length-1]=null;//删除数组最后一位
count--;
}
}
</script></head>
<body>
<?php
$GLOBALS["classid"] =61;
$jibie=1;
$sql="select * from `phome_enewsclass` where bclassid=0 and classid=61 order by myorder";
$result=mysql_query($sql,$Conn);
if(mysql_num_rows($result)>0)
TreeMenu($Conn,$result,$jibie,$classid);
function TreeMenu($Conn,$result,$jibie) //进入函数循环
{
$numrows=mysql_num_rows($result);
echo "<table cellpadding='0' cellspacing='0' border='0'>";
for($rows=0;$rows<$numrows;$rows++)
{
$menu=mysql_fetch_array($result);
$sql="select * from phome_enewsclass where bclassid=$menu[classid] order by myorder";
$result_sub=mysql_query($sql,$Conn);
echo "<tr>";
//echo(mysql_num_rows($result_sub));
//如果该菜单项目有子菜单,则添加JavaScript onClick语句
if(mysql_num_rows($result_sub)>0)
{
echo "<td></td>";
echo "<td width='100' align='left' valign='top' class='Menu' onClick='javascript:ShowMenu(".$GLOBALS['classid'].");'>";
}
else
{
echo "<td ></td>";
echo "<td width='100' align='left' valign='top' class='Menu'>";
}
if($menu[classpath]!="") {
echo "<a href='#'>$menu[classname]</a> ";
//echo "$menu[classpath]</td></tr>" ;
}
else
{ echo "</td> </tr>"; }
if(mysql_num_rows($result_sub)>0)
{
echo "<tr id=Menu".$GLOBALS["classid"]++." style='display:none'>";
echo "<td width='20'> </td>";
echo "<td>";
//将级数加1
$jibie++;
TreeMenu($Conn,$result_sub,$jibie);
$jibie--;
echo "</td></tr>";
}
//显示下一菜单
}
echo "</table>";
}
?>
我想要的效果,点击大类显示小类,
比如3个小类
点第一小类,小类展开,
点第二个类,第一个小类和第三个小类收缩,第二个小类展开,点第三个小类,第一个和第二个小类收缩,怎样实现
<?php
$Conn=mysql_connect("localhost:3306","root","123456");
$db=mysql_select_db("empirecmd"); //打开数据库
mysql_query("SET NAMES 'gb2312'"); //避免乱码
$tpye=trim($_GET["tpye"]);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<LINK href="http://www.w-w365.com/skin/jr/css/css.css" type=text/css rel=stylesheet>
<head>
<script type="text/javascript">
var count=0;//做计数器
var limit=new Array();//用于记录当前显示的哪几个菜单
var countlimit=1;//同时打开菜单数目,可自定义
function ShowMenu(ID)
{
obj = eval("Menu" + ID);
if(obj.style.display=="none")
{
obj.style.display="block";
if (count<countlimit) {//限制2个
limit[count]=ID;//录入数组
count++;
}
else {
eval("Menu" + limit[0]).style.display = "none";
for (i=0;i<limit.length-1;i++) {limit[i]=limit[i+1];}//数组去掉头一位,后面的往前挪一位
limit[limit.length-1]=ID;
}
}
else
{
obj.style.display="none";
var j;
for (i=0;i<limit.length;i++) {if (limit[i]==ID) j=i;}//获取当前点击的菜单在limit数组中的位置
for (i=j;i<limit.length-1;i++) {limit[i]=limit[i+1];}//j以后的数组全部往前挪一位
limit[limit.length-1]=null;//删除数组最后一位
count--;
}
}
</script></head>
<body>
<?php
$GLOBALS["classid"] =61;
$jibie=1;
$sql="select * from `phome_enewsclass` where bclassid=0 and classid=61 order by myorder";
$result=mysql_query($sql,$Conn);
if(mysql_num_rows($result)>0)
TreeMenu($Conn,$result,$jibie,$classid);
function TreeMenu($Conn,$result,$jibie) //进入函数循环
{
$numrows=mysql_num_rows($result);
echo "<table cellpadding='0' cellspacing='0' border='0'>";
for($rows=0;$rows<$numrows;$rows++)
{
$menu=mysql_fetch_array($result);
$sql="select * from phome_enewsclass where bclassid=$menu[classid] order by myorder";
$result_sub=mysql_query($sql,$Conn);
echo "<tr>";
//echo(mysql_num_rows($result_sub));
//如果该菜单项目有子菜单,则添加JavaScript onClick语句
if(mysql_num_rows($result_sub)>0)
{
echo "<td></td>";
echo "<td width='100' align='left' valign='top' class='Menu' onClick='javascript:ShowMenu(".$GLOBALS['classid'].");'>";
}
else
{
echo "<td ></td>";
echo "<td width='100' align='left' valign='top' class='Menu'>";
}
if($menu[classpath]!="") {
echo "<a href='#'>$menu[classname]</a> ";
//echo "$menu[classpath]</td></tr>" ;
}
else
{ echo "</td> </tr>"; }
if(mysql_num_rows($result_sub)>0)
{
echo "<tr id=Menu".$GLOBALS["classid"]++." style='display:none'>";
echo "<td width='20'> </td>";
echo "<td>";
//将级数加1
$jibie++;
TreeMenu($Conn,$result_sub,$jibie);
$jibie--;
echo "</td></tr>";
}
//显示下一菜单
}
echo "</table>";
}
?>
<ul></ul>
<div id="L11" onclick="showTree(1,11);">
<ul>第二级分类 ID=11</ul>
<div……</div>
</div>
<div id="L12">
<ul>第二级分类 ID=12</ul>
<div……</div>
</div>
<div id="L13">
<ul>第二级分类 ID=13</ul>
<div……</div>
</div>
</div>
<div id="L2">
</div>
<div id="L3">
</div>
……
<script language="javascript">
function showTree(ParentId,ThisId)
{
var dom = document.getElementById("L"+ParentId).getElementsByTagName("div");
for(var i=0;i<dom.length,i++)
{
if(dom[i].id=="L"+ThisId)
{
dom[i].style.display = "";
}
else
{
dom[i].style.display = "none";
}
}
}
</script>