PHP里生成的水平菜单

WBOY
Release: 2016-06-23 14:10:37
Original
917 people have browsed it

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

<!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">
Copy after login

<?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));?>
Copy after login

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

求帮忙


回复讨论(解决方案)

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

你贴出截图中的 html 代码

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

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

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template