Ê÷ÐͲ˵¥Ôںܶà×ÀÃæÓ¦ÓÃϵͳÖж¼Óзdz£¹ã·ºµÄÓ¦Óã¬ÆäÖ÷ÒªÓŵãÊǽṹÇåÎú£¬ÀûÓÚʹÓÃÕ߷dz£Çå³þµÄÖªµÀÄ¿Ç°×Ô¼ºËùÔÚµÄλÖᣵ«ÔÚwebÉÏÊ÷ÐͲ˵¥µÄÓ¦ÓÃÒòΪûÓÐÀíÏëµÄÏÖ³É×é¼þ¿ÉÒÔÄùýÀ´Ö±½ÓʹÓã¬ËùÒÔÒ»°ãµÄÇé¿öÏ£¬³ÌÐòÔ±Ö÷ÒªÊÇͨ¹ýJavaScriptÀ´ÊµÏÖһЩ¼òµ¥µÄÊ÷Ðͽṹ²Ëµ¥£¬µ«ÕâЩ²Ëµ¥ÍùÍù¶¼ÊÇÊÂÏȶ¨ºÃ¸÷²Ëµ¥ÏîÄ¿£¬ÒÔ¼°¸÷²Ëµ¥ÏîÄ¿Ö®¼äµÄ²ã´Î¹Øϵ£¬²»ÀûÓÚÀ©³ä£¬Ò»µ©ÐèÒªÁíÒ»¸ö²Ëµ¥½á¹¹Ê±£¬ÍùÍù»¹ÐèÒªÖØбàд£¬Òò´ËʹÓÃÆðÀ´²»ÊǺܷ½±ã¡£
¾¹ý¶Ôº¯ÊýµÝ¹éµÄÑо¿£¬ÎÒ·¢ÏÖÕâÖÖÊ÷ÐͲ˵¥¿ÉÒÔͨ¹ýµÝ¹éº¯Êý£¬Ê¹Ê÷ÐͲ˵¥µÄÏÔʾʵÏÖ¶¯Ì¬±ä»¯£¬²¢Ã»Óм¶ÊýµÄÏÞÖÆ¡£ÏÂÃæ¾ÍÊÇÎÒÓÃphp,MySQL,JavaScriptдµÄÒ»¸ö¶¯Ì¬Ê÷ÐͲ˵¥µÄ´¦Àí´úÂ룬Èç¹û´ó¼ÒÓÐÐËȤµÄ»°£¬¾ÍºÍÎÒÒ»ÆðÀ´¿´¿´ÎÒÊÇÈçºÎʵÏֵİɣº£©
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÒ»¸öÊý¾Ý¿â£¬ÔÚÕâ¸öÊý¾Ý¿âÖУ¬ÎÒÃǽ¨Á¢ÒÔÏÂÒ»ÕÅ±í£º
CREATE TABLE menu (
id tinyint(4) NOT NULL auto_increment,
parent_id tinyint(4) DEFAULT '0' NOT NULL,
name varchar(20),
url varchar(60),
PRIMARY KEY (id)
);
INSERT INTO menu VALUES ( '1', '0', 'ÈËʹÜÀí', '');
INSERT INTO menu VALUES ( '2', '0', 'ͨѶ½»Á÷', '');
INSERT INTO menu VALUES ( '3', '1', 'µµ°¸¹ÜÀí', '');
INSERT INTO menu VALUES ( '4', '1', '¿¼ÇÚ¹ÜÀí', 'http://localhost/personal/attendance.php');
INSERT INTO menu VALUES ( '5', '2', 'ͨѶ¼', '');
INSERT INTO menu VALUES ( '6', '2', 'ÍøÂç»áÒé', '');
INSERT INTO menu VALUES ( '7', '3', 'ÐÂÔöµµ°¸', 'http://localhost/personal/add_achive.php');
INSERT INTO menu VALUES ( '8', '3', '²éѯµµ°¸', 'http://localhost/personal/search_archive.php');
INSERT INTO menu VALUES ( '9', '3', 'ɾ³ýµµ°¸', 'http://localhost/personal/delete_archive.php');
INSERT INTO menu VALUES ( '10', '5', 'ÐÂÔöͨѶ¼Ç¼','http://localhost/communication/add_address.php');
INSERT INTO menu VALUES ( '11', '5', '²éѯͨѶ¼Ç¼', http://localhost/communication/search_address.php');
INSERT INTO menu VALUES ( '12', '5', 'ɾ³ýͨѶ¼Ç¼', http://localhost/communication/delete_address.php');
INSERT INTO menu VALUES ( '13', '6', 'ÕÙ¿ª»áÒé', 'http://localhost/communication/convence_meeting.php');
INSERT INTO menu VALUES ( '14', '6', '»áÒé²éѯ', 'http://localhost/communication/search_meeting.php');
function ShowMenu(MenuID)
{
if(MenuID.style.display=="none")
{
MenuID.style.display="";
}
else
{
MenuID.style.display="none";
}
}
<!-- ±í¸ñÑùʽ -->
TD {
FONT-FAMILY: "Verdana", "ËÎÌå"; FONT-SIZE: 12px; LINE-HEIGHT: 130%; letter-spacing:1px
}
<!-- ³¬¼¶Á¬½ÓÑùʽ -->
A:link {
COLOR: #990000; FONT-FAMILY: "Verdana", "ËÎÌå"; FONT-SIZE: 12px; TEXT-DECORATION: none; letter-spacing:1px
}
A:visited {
COLOR: #990000; FONT-FAMILY: "Verdana", "ËÎÌå"; FONT-SIZE: 12px; TEXT-DECORATION: none; letter-spacing:1px
}
A:active {
COLOR: #990000; FONT-FAMILY: "Verdana", "ËÎÌå"; FONT-SIZE: 12px; TEXT-DECORATION: none; letter-spacing:1px
}
A:hover {
COLOR: #ff0000; FONT-FAMILY: "Verdana", "ËÎÌå"; FONT-SIZE: 12px; TEXT-DECORATION: underline; letter-spacing:1px
}
<!-- ÆäËûÑùʽ -->
.Menu {
COLOR:#000000; FONT-FAMILY: "Verdana", "ËÎÌå"; FONT-SIZE: 12px; CURSOR: hand
}
<html>
<head>
<link href='style.css' rel=stylesheet>
<script language="JavaScript" src="TreeMenu.js"></script>
</head>
<body>
<?php
//»ù±¾±äÁ¿ÉèÖÃ
$GLOBALS["ID"] =1; //ÓÃÀ´¸ú×ÙÏÂÀ²Ëµ¥µÄIDºÅ
$layer=1; //ÓÃÀ´¸ú×Ùµ±Ç°²Ëµ¥µÄ¼¶Êý
//Á¬½ÓÊý¾Ý¿â
$Con=mysql_connect("localhost","root","");
mysql_select_db("work");
//ÌáÈ¡Ò»¼¶²Ëµ¥
$sql="select * from menu where parent_id=0";
$result=mysql_query($sql,$Con);
//Èç¹ûÒ»¼¶²Ëµ¥´æÔÚÔò¿ªÊ¼²Ëµ¥µÄÏÔʾ
if(mysql_num_rows($result)>0) ShowTreeMenu($Con,$result,$layer,$ID);
//=============================================
//ÏÔʾÊ÷ÐͲ˵¥º¯Êý ShowTreeMenu($con,$result,$layer)
//$con£ºÊý¾Ý¿âÁ¬½Ó
//$result£ºÐèÒªÏÔʾµÄ²Ëµ¥¼Ç¼¼¯
//layer£ºÐèÒªÏÔʾµÄ²Ëµ¥µÄ¼¶Êý
//=============================================
function ShowTreeMenu($Con,$result,$layer)
{
//È¡µÃÐèÒªÏÔʾµÄ²Ëµ¥µÄÏîÄ¿Êý
$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 menu where parent_id=$menu[id]";
$result_sub=mysql_query($sql,$Con);
echo "<tr>";
//Èç¹û¸Ã²Ëµ¥ÏîÄ¿ÓÐ×Ӳ˵¥£¬ÔòÌí¼ÓJavaScript onClickÓï¾ä
if(mysql_num_rows($result_sub)>0)
{
echo "<td width='20'><img src='folder.gif' border='0'></td>";
echo "<td class='Menu' onClick='javascript:ShowMenu(Menu".$GLOBALS["ID"].");'>";
}
else
{
echo "<td width='20'><img src='file.gif' border='0'></td>";
echo "<td class='Menu'>";
}
//Èç¹û¸Ã²Ëµ¥ÏîĿûÓÐ×Ӳ˵¥£¬²¢Ö¸¶¨Á˳¬¼¶Á¬½ÓµØÖ·£¬ÔòÖ¸¶¨Îª³¬¼¶Á¬½Ó£¬
//·ñÔòÖ»ÏÔʾ²Ëµ¥Ãû³Æ
if($menu[url]!="")
echo "<a href='$menu[url]'>$menu[name]</a>";
else
echo $menu[name];
echo "
</td>
</tr>
";
//Èç¹û¸Ã²Ëµ¥ÏîÄ¿ÓÐ×Ӳ˵¥£¬ÔòÏÔʾ×Ӳ˵¥
if(mysql_num_rows($result_sub)>0)
{
//Ö¸¶¨¸Ã×Ӳ˵¥µÄIDºÍstyle£¬ÒÔ±ãºÍonClickÓï¾äÏà¶ÔÓ¦
echo "<tr id=Menu".$GLOBALS["ID"]++." style='display:none'>";
echo "<td width='20'> </td>";
echo "<td>";
//½«¼¶Êý¼Ó1
$layer++;
//µÝ¹éµ÷ÓÃShowTreeMenu()º¯Êý£¬Éú³É×Ӳ˵¥
ShowTreeMenu($Con,$result_sub,$layer);
//×Ӳ˵¥´¦ÀíÍê³É£¬·µ»Øµ½µÝ¹éµÄÉÏÒ»²ã£¬½«¼¶Êý¼õ1
$layer--;
echo "</td></tr>";
}
//¼ÌÐøÏÔʾÏÂÒ»¸ö²Ëµ¥ÏîÄ¿
}
echo "</table>";
}
?>
</body>
</html>