¾¹ý¶Ôº¯ÊýµÝ¹éµÄÑо¿£¬ÎÒ·¢ÏÖÕâÖÖÊ÷ÐͲ˵¥¿ÉÒÔͨ¹ýµÝ¹éº¯Êý£¬Ê¹Ê÷ÐͲ˵¥µÄÏÔʾʵÏÖ¶¯Ì¬±ä»¯£¬²¢Ã»Óм¶ÊýµÄÏÞÖÆ¡£ÏÂÃæ¾ÍÊÇÎÒÓÃ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)
);
ÕâÕűíÖÐ
id ΪË÷Òý
parent_id ÓÃÀ´±£´æÉÏÒ»¼¶²Ëµ¥µÄidºÅ£¬Èç¹ûÊÇÒ»¼¶²Ëµ¥ÔòΪ0
name Ϊ²Ëµ¥µÄÃû³Æ£¬Ò²¾ÍÊÇÒªÔÚÒ³ÃæÉÏÏÔʾµÄ²Ëµ¥ÄÚÈÝ
url Èç¹ûij²Ëµ¥ÎªÄ©¼¶²Ëµ¥£¬ÔòÐèÒªÖ¸¶¨¸ÃÁ¬½ÓµÄurlµØÖ·£¬Õâ¸ö×ֶξÍÊÇÓÃÀ´±£´æ´ËµØÖ·µÄ£¬ÆäËû·ÇÄ©¼¶²Ëµ¥£¬¸Ã×Ö¶ÎΪ¿Õ
ºÃÁË£¬Êý¾Ý¿âÓÐÁË£¬Äã¾Í¿ÉÒÔÌí¼ÓһЩ¼Ç¼ÁË£¬ÏÂÃæÊÇÎÒ×ö²âÊÔµÄʱºò£¬Ê¹ÓõÄһЩ¼Ç¼£º
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');
ÔÚÌí¼Ó¼Ç¼µÄʱºò£¬Ò»¶¨Òª×¢Ò⣬·ÇÒ»¼¶²Ëµ¥µÄparent_idÒ»¶¨ÒªÖ¸¶¨ÎªÉϼ¶²Ëµ¥µÄIDºÅ£¬·ñÔòÄãµÄ²Ëµ¥ÊDz»»áÏÔʾ³öÀ´µÄ£º£©
ºÃÁË£¡ÓÐÁËÊý¾Ý¿â£¬ÏÂÃæ¾ÍÊÇͨ¹ýphp,JavaScript°Ñ²Ëµ¥´ÓÊý¾Ý¿âÖжÁ³öÀ´£¬²¢ÏÔʾ³öÀ´ÁË£º£©
1¡¢JavaScript½Å±¾£º
function ShowMenu(MenuID)
{
if(MenuID.style.display=="none")
{
MenuID.style.display="";
}
else
{
MenuID.style.display="none";
}
}
Õâ¸ö½Å±¾ºÜ¼òµ¥£¬¾ÍÊÇÓÃÀ´ÏìÓ¦µã»÷ij¸ö²Ëµ¥±»µã»÷µÄʼþµÄ¡£
2¡¢CSSÎļþ£º
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
}
¶¨ÒåÁËһЩ»ù±¾µÄÑùʽÐÅÏ¢£¬±ÈÈç×ÖÌ壬ÑÕÉ«£¬³¬¼¶Á¬½ÓµÄÑùʽµÈ£¬Èç¹ûÄãÏë¸Ä±äÑùʽµÄ»°£¬Ö»ÒªÐÞ¸ÄÕâÀï¾ÍÐÐÁË£¡
3¡¢ÏÂÃæ¾ÍÊÇÎÒµÄ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 "
"; | ";
} else { echo " | "; | ";
} //Èç¹û¸Ã²Ëµ¥ÏîĿûÓÐ×Ӳ˵¥£¬²¢Ö¸¶¨Á˳¬¼¶Á¬½ÓµØÖ·£¬ÔòÖ¸¶¨Îª³¬¼¶Á¬½Ó£¬ //·ñÔòÖ»ÏÔʾ²Ëµ¥Ãû³Æ if($menu[url]!="") echo "$menu[name]"; else echo $menu[name]; echo " |
}
?>
ÔÚÉÏÃæµÄphpÒ³ÃæÀïÃ棬ÎÒ¶¨ÒåÁËÒ»¸öº¯ÊýShowTreeMenu()£¬Í¨¹ýÕâ¸öº¯ÊýµÄµ÷Ó㬻á´ÓÊý¾Ý¿âÖеݹéµÄµ÷³öÿ¸ö²Ëµ¥ÏîÄ¿£¬²¢ÏÔʾÔÚÒ³ÃæÉÏÁË£º£©