Heim  >  Artikel  >  Backend-Entwicklung  >  PHP里生成的水平菜单

PHP里生成的水平菜单

WBOY
WBOYOriginal
2016-06-23 14:10:37865Durchsuche

遍历目录及文件后,把列表生成水平菜单,但怎么弄都弄不出预期的效果
预期的效果:
代码如下:

<!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="utf-8" /><script src="SpryMenuBar.js" type="text/javascript"></script><link href="SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" /><title>menu</title></head><body><ul id="MenuBar1" class="MenuBarHorizontal">

<?php $path = '.';//当前目录 function getfiles($path) {	 echo "<li><a class='MenuBarItemSubmenu' href='".$path."'>".$path."</a>";	echo '<ul>';	 if(!is_dir($path)) return;	$handle  = opendir($path);	while( false !== ($file = readdir($handle)))	{		//echo "<li><a class='MenuBarItemSubmenu' href='".$path."'>".$path."</a>";		//echo '<ul>';		if($file != '.'  &&  $file!='..')		{						$path2= $path.'/'.$file;			echo "<li><a href='".$path2."' class='MenuBarItemSubmenu'>".$path2."</a>";			echo "<ul>";			if(is_dir($path2))			{				//echo $file;//输出路径+目录名		       getfiles($path2);			}else			{			 	echo "<li><a href='".$path."/".$file."'>".$file."</a></li>";//输出的文件名			}			echo "</ul></li>";		}		//echo "</ul></li>";	}	echo "</ul></li>";}print_r( getfiles($path));?>

</ul><script type="text/javascript">var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"SpryMenuBarDownHover.gif", imgRight:"SpryMenuBarRightHover.gif"});</script></body></html>

求帮忙


回复讨论(解决方案)

显然是你输出的数据有问题

你贴出截图中的 html 代码

显然是你输出的数据有问题

你贴出截图中的 html 代码
我贴的图和代码是没有关系的,我是想说要用代码做成图那样子的

有比较才能有鉴别
这么浅显的道理都不知道吗?

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn