PHP¿Í ÀÚ¹Ù½ºÅ©¸³Æ®¸¦ ÀÌ¿ëÇÑ µå·Ó´Ù¿î ¸Þ´º |
|
|
 |
14³â Àü |
PHP¿Í ÀÚ¹Ù½ºÅ©¸³Æ®¸¦ ÀÌ¿ëÇÑ µå·Ó´Ù¿î ¸Þ´º
Á¦¸ñ ±×´ë·Î php¿Í javascript ¸¦ ÀÌ¿ëÇÑ µå·Ó´Ù¿î ¸Þ´º ¼Ò½ºÀÔ´Ï´Ù. ¿À·¡Àü¿¡ ±¦Âú´Ù ½Í¾î¼ ÀúÀå Çسù´ø ¼Ò½º¶ó Ãâó´Â ±â¾ïÀÌ ¾È³ª´Âµ¥, ÇØ¿Ü »çÀÌÆ®¿¡¼ Æۿ°ɷΠ±â¾ïµË´Ï´Ù.
<script type="text/javascript">
<!--
function toggle(id) {
if(document.getElementById) {
var el = document.getElementById(id);
el.style.display = (el.style.display == 'none') ? 'block' : 'none';
}
}
//-->
</script>
</head>
<body>
<?php
// menu title => menu target
$menu = array('Menu One'=>array('Page One'=>'blist_menu.php?pg=1',
'Page Two'=>'blist_menu.php?pg=2'),
'Menu Two'=>array('Page Three'=>'blist_menu.php?pg=3',
'Page Four'=>'blist_menu.php?pg=4'),
'Menu Three'=>array('Page Five'=>'blist_menu.php?pg=5',
'Menu Four'=>array('Page Six'=>'blist_menu.php?pg=6',
'Page Seven'=>'blist_menu.php?pg=7')));
// alternative method to using cookies
function array_search_recursive($needle, $haystack) {
$pos = null;
$keys = array_keys($haystack);
while(!$pos && (list($garbage, $value)=each($keys))) {
if(is_scalar($haystack[$value])) {
if($haystack[$value] === $needle)
$pos[] = $value;
} elseif(is_array($haystack[$value])) {
if($pos = array_search_recursive($needle, $haystack[$value]))
array_unshift($pos, $value);
}
}
return $pos;
}
// recursive function to draw menu
function draw_menu($menu, $preserve, &$id) {
if($id == 0)
echo "<div id=\"$id\">\r\n<ul>\r\n";
else
echo "<div id=\"$id\" style=\"display:none;\">\r\n<ul>\r\n";
$id += 1;
foreach($menu as $key=>$value) {
if(is_array($value)) {
if(@in_array($key, $preserve))
$toggle = $id;
echo "<li><a href=\"#\" onclick=\"toggle($id);\">$key</a></li>\r\n";
draw_menu($value, $preserve, $id);
}
else {
echo "<li class=\"file\">";
if(@in_array($key, $preserve))
echo "<a class=\"live\" href=\"$value\">$key</a>";
else
echo "<a href=\"$value\">$key</a>";
echo "</li>\r\n";
}
}
echo "</ul>\r\n</div>\r\n";
if(isset($toggle))
echo "<script language=\"javascript\">toggle($toggle);</script>\r\n";
}
$id = 0;
$base = basename($_SERVER['PHP_SELF']);
$self = isset($_SERVER['QUERY_STRING']) ? $base.'?'.$_SERVER['QUERY_STRING'] : $base;
$preserve = array_search_recursive($self, $menu);
draw_menu($menu, $preserve, $id);
?>
|
|
̵̧ : 297 |
̵̧
¸ñ·Ï
|
|