2016-12-15 32 views
0

我有一個導航欄,有3個按鈕,說家,電影和流派。點擊流派應打開下拉列表,從數據庫生成的所有流派的列表,並點擊每個流派,genrepage包含所選類型的電影列表出現。但是當我嘗試從主頁訪問時,流派按鈕(帶下拉列表)不起作用。但它適用於任何其他頁面。我正在使用Bootstrap 3.3.7 navbar和任何幫助將不勝感激。Bootstrap導航欄下拉菜單不能只從一個頁面工作

我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> 
+3

歡迎來到StackOverflow,你的問題應該包含一個最小,完整和可驗證的例子,[這裏是如何](http://stackoverflow.com/help/mcve)。另外,請刪除PHP並提供生成的標記。另一件事,你如何包含Bootstrap文件?您是否已驗證這些文件是否包含在主頁上? – hungerstar

回答

0

如果啓動菜單未能從主頁導航離開時的工作,因爲它聽起來像bootstrap.js不上你的子頁面運行的下拉工作。檢查您的網絡選項卡> js,並查看bootstrap.min.js是否正在加載或查看源代碼。

相關問題