我有一个带有 3 个按钮的导航栏,分别是“主页”、“电影”和“流派”。单击流派应打开下拉列表,其中包含从数据库生成的所有流派列表,然后单击每个流派,显示包含所选流派电影列表的流派页面。但是当我试图从主页访问它时,流派按钮(带有下拉菜单)不起作用。但它适用于任何其他页面。我正在使用 Bootstrap 3.3.7 导航栏,我们将不胜感激。
我的 navbar.php
<?php
/*
array of pages
this builds the navigation list
format:
filename => URL name
*/
$navArray = array(
'index' => 'Home',
'film' => 'Films',
'genre' => 'Genre',
);
?>
//some html code here
<?php
foreach($navArray as $key => $nav){
//assign active class to currently active page
if(strstr($_SERVER['SCRIPT_NAME'], $key))
$active = ' active';
else $active = '';
//if Genre is selected, display dropdown menu
if($nav=='Genre'){
echo '<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Genre<span class="caret"></span></a>
<ul class="dropdown-menu">';
//generate dropdown from database, giving the list of genres
$queryGenreList="SELECT genre.`name`
from genre;
";
$resultGenreList=$db->query($queryGenreList);
if($resultGenreList->num_rows > 0){
while($row = $resultGenreList->fetch_assoc()){
echo '<li><a href="genreInfo.php?name='.$row["name"].'">'.$row["name"].'</a></li>';
}
}
echo '</ul>
</li>';
}
echo"<li class='nav-item".$active.";'>";
if($nav!='Genre'){
echo"<a class='nav-link' href=".$key.".php>".$nav."</a>";
}
}
?>
</li>
最佳答案
如果 Bootstrap 菜单在离开主页时无法正常工作,因为听起来好像 bootstrap.js 没有在您的子页面上运行以使下拉菜单正常工作。检查您的网络选项卡 > js 并查看是否正在加载 bootstrap.min.js 或查看源代码。
关于php - Bootstrap 导航栏下拉菜单仅在一页上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41166702/