导航到另一个页面后,bootstrap下拉列表变得无法使用

时间:2015-03-05 02:12:56

标签: javascript php jquery html

我有3个.php文件,它们是index.php,load_file.php和register.php

  1. 在index.php中,包含导航,每个导航都有下拉列表,我调用此导航和数据库中的下拉列表。并且index.php也有到register.php的链接,注意:load_file.php包含在这个文件中
  2. 在load_file.php中,包含用于检查页面值的代码,使用if($ _ GET ['page']),并使用switch-case触发每个值
  3. register.php,只是一个普通的表格
  4.   

    我的问题是,在我通过在浏览器中键入?page = register导航到register.php之后,我在index.php文件中的下拉列表变得无法使用

    :: UPDATE ::

    这是我的 index.php 文件

    <?php
        session_start();
        require_once './model/functions.php';
    
        if(isset($_GET["category"])){
            $index_page= $_GET["category"];
            $index_sub_page= null;
        }elseif (isset ($_GET["sub_category"])) {   
            $index_sub_page = $_GET["sub_category"];
            $index_page= null;
        }else{
            $index_sub_page= null;
            $index_page= null;
        }
        
        if($_POST){      
            $username = $_POST["username"];
            $password = $_POST["password"];
            
            if(check_username_and_password_from_users($username, $password)){
                $_SESSION["username"] = $username;
            }
        }
    ?>
    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="UTF-8">
    		<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    		<title>Learn Bootstrap</title>
    		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
    	</head>
    	<body>
                <div id="TopContainer" class="container">
                    <div class="pull-right navbar-default">
                        <ul class="nav navbar-nav">
                            <?php if(isset($_SESSION["username"])){ ?>
                            <li class="dropdown">
                                <a class="dropdown-toggle" href="#" data-toggle="dropdown"><?php echo $_SESSION["username"]; ?></a>
                                <div class="dropdown-menu" style="padding: 17px;">
                                    <a href="logout.php">Logout</a>
                                </div>
                            </li>
                            <?php }else{ ?>
                          <!--dropdown here -->
                            <li class="dropdown">
                                <a class="dropdown-toggle" href="#" data-toggle="dropdown" id="login">Dropdown</a>
                                <div class="dropdown-menu" style="padding:17px;">
                                    <form id="loginform" method="post" action="index.php" class="form">
                                        <div class="form-group">
                                            <input class="form-control" type="text" name="username" id="username" placeholder="username">
                                        </div>
                                        <div class="form-group">
                                            <input class="form-control" type="password" name="password" id="password" placeholder="password">
                                        </div>
                                        <input type="submit" value="Submit">
                                    </form>
                                </div>
                            </li>
                            <li><a href="?page=register">Register</a></li>
                            <?php } ?>
                            <li><a href="#">FAQs</a></li>
                            <li><a href="#">Twitter</a></li>
                            <li><a href="#">Facebook</a></li>
                        </ul>
                    </div>
                </div>
                <div id="logo" class="container">
                    <div class="col-md-6">
                        <a class="navbar no-margin" href="#"><img src="picture/LogoSaya.png"></a>
                    </div>
                    <div class="col-md-6">
                        <div class="col-md-6 pull-right">
                            <div class="input-group input-group-sm">
                                <span class="input-group-btn">
                                    <button class="btn btn-default" type="button">Go!</button>
                                </span>
                                    <input type="text" class="form-control" placeholder="Search for...">  
                            </div>
                        </div>
                    </div>
                </div>
                <nav class="container">
                    <div class="navbar navbar-default">
                        <ul class="nav navbar-nav">
                            <?php
                                $subject_set =  find_all_subjects();
                                while($subject = mysqli_fetch_assoc($subject_set)){
                            ?>
                            
                            <li>
                                <a id="dLabel" data-target="#" href="?subject=<?php echo urlencode($subject["id"]);?>" data-toggle="dropdown" aria-haspopup="true" role="button">
                                    <?php echo $subject["name"];?>
                                    <span class="caret"></span>
                                </a>
                              <!--dropdown here -->
                                <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
                                    <?php
                                        $page_set = find_pages_from_subjects($subject["id"]);
                                        while($page = mysqli_fetch_assoc($page_set)){
                                    ?>
                                        <li>
                                            <a href="?category=<?php echo urlencode($page["id"]);?>"><?php echo $page["name"];?></a>                                        
                                            <ul>
                                                <?php
                                                    $sub_page_set = find_sub_pages_from_pages($page["id"]);
                                                    while($sub_page = mysqli_fetch_assoc($sub_page_set)){
                                                ?>
                                                <li>
                                                    <a href="?sub_category=<?php echo urlencode($sub_page["id"]);?>"><?php echo $sub_page["name"];?></a>
                                                </li>
                                                <?php
                                                    }
                                                    clear_result($sub_page_set);
                                                ?>
                                            </ul>
                                        </li>                  
                                    <?php
                                        }
                                        clear_result($page_set);
                                    ?>
                                </ul>
                            </li>
                            
                            <?php
                                }
                                clear_result($subject_set);
                            ?>
                        </ul>
                    </div>
                </nav>
                <div class="container">
                    <?php
                        include "load_files.php"; //this is to load the files
                    ?> 
                </div>
                <script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
                <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
    	</body>
    </html>

    导航register.html,我使用此代码

    <li><a href="?page=register">Register</a></li>
    

    如你所见,我把代码放在index.php下面的代码

               <?php
                    include "load_files.php"; //this is to load file
                ?> 
    

    这是我的 load_files.php

    <?php
        if($_GET){
            switch ($_GET['page']) {   
                case 'register':
                    if(!file_exists("register.html")){
                        die("Sorry Empty Page");
                    }
                    include 'register.html';
                    break;
                default:
                    break;
            }
        }
    ?>

2 个答案:

答案 0 :(得分:0)

似乎是一个事件处理程序问题。我看看你是如何添加事件处理程序的,看看处理程序是否会以某种方式被删除。

答案 1 :(得分:0)

<强> ::解决::

  

我的问题是,在我通过在浏览器中键入?page = register导航到register.php之后,我在index.php文件中的下拉列表变得无法使用

发生这个问题是因为,我有2个

<script src="jquery.js"></script>

,在index.php和register.html .by中删除register.html中的一个将解决问题