我已经尝试了几乎所有可在线获得的解决方案但无法获得课程="活跃"为每个菜单部分动态更改。
当有人点击顶级菜单项时,它会打开第二级菜单,如果有人点击该部分中的第二级菜单项="活动"需要保留在顶级菜单li标签上。
我有以下函数生成我的引导程序菜单:
function getMenu() {
global $connection;
mysqli_select_db($connection, "c9");
$query = ("SELECT testName, testId FROM testType");
$result_set = mysqli_query($connection, $query);
while ($row = mysqli_fetch_array($result_set)) {
$testId = $row['testId'];
$testName = $row['testName'];
echo '<li>'; //This is where class="active" needs to be added
echo '<a href="#"><span class="nav-label">'.$testName.'</span></a>';
echo '<ul class="nav nav-second-level collapse">';
echo '<li><a href="/dashboard/?type=doTest&testId='.$testId.'">Summary Report</a></li>';
echo '<li><a href="/dashboard/?type=doTest&testId='.$testId.'">Add Data</a></li>';
echo '</ul>';
echo '</li>';
}
}
菜单结构如下:
<ul class="nav metismenu" id="side-menu">
<li class="active">
<a href="/">
<span class="nav-label">Summary</span>
<ul class="nav nav-second-level collapse in">
<li><a href="dashboard_5.html">Reports</a></li>
</ul>
</li>
<li><a href="#">
<span class="nav-label">Temperature</span>
<ul class="nav nav-second-level collapse">
<li><a href="/dashboard/?type=doTest&testId=1">Summary Report</a></li>
<li><a href="/dashboard/?type=doTest&testId=1">Add Data</a></li>
</ul>