我的php脚本中的所选菜单有问题。
当我点击我的某个菜单选项时,它不会将li类设置为选中。
我现在正在寻找几个小时但仍然无法找到它。在正手感谢帮助!!
这里是PHP代码:
private $selectedmenu = '';
public function set_selectedmenu($set_selectedmenu) {
$this->selectedmenu = $set_selectedmenu;
}
public function html() {
$html_menu='';
$menu = array(
'test'=>array('optie'=>'test', 'url'=>'index.php?page=test'),
'test2'=>array('optie'=>'test2', 'url'=>'index.php?page=test2'),
'test3'=>array('optie'=>'test3', 'url'=>'index.php?page=test3'),
'test4'=>array('optie'=>'test4', 'url'=>'index.php?page=test4'),
);
foreach($menu as $key => $menuoptie) {
if ($key==$this->selectedmenu) {
$class=' class="selected"';
}else{
$class='';
}
$html_menu.="<li{$class}><a href=\"{$menuoptie['url']}\">{$menuoptie['optie']}</a></li>\n";
}
return(
<<<EOT
<!DOCTYPE html>
<html>
<head>
<title>{$this->html_titel}</title>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="stylesheet/css.css" />
</head>
<body>
<ul class="menu">
{$html_menu}
</ul>
</body>
</html>
EOT
);
}
关注CSS:
.menu{
padding-left: 117px;
margin-top: 10px;
list-style: none;
overflow: hidden;
margin-left:40px;
}
.menu li {
padding: 0;
margin: 0;
float: left;
width: 200px;
border: 1px solid black;
}
.menu li:hover a {
background-color:#FF8055;
font-weight:bold;
}
.menu li a {
text-align:center;
background-color:#f60;
text-decoration: none;
display: block;
padding: 10px 0px 10px 10px;
text-align: left;
font-weight:bold;
color:white;
}
.menu li.selected a{
background-color: black;
text-decoration:underline;
}