【问题标题】:Why does my dropdown menu not work when using Include?为什么我的下拉菜单在使用包含时不起作用?
【发布时间】:2020-12-03 20:26:31
【问题描述】:

所以我有一个导航栏(下面的代码),当它被硬编码到我的网页中时它可以工作,但是当我将它分开并尝试使用“包含”时,附加到我的登录按钮的下拉菜单不再工作。所有文件都在 php 中,我主要使用引导程序。想知道是否有人知道这不起作用的原因以及可能的解决方案。

<!DOCTYPE html>
<html>
    <head>
        <title>Hands On Lab</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>    
        <script src="https://cdn.jsdelivr.net/mark.js/7.0.0/jquery.mark.min.js"></script>
    </head>
    <style>
        mark {
        background: orange;
        color: black;
        }
    </style>
 <body>
 <nav class="navbar navbar-inverse">
            <div class="container-fluid">
                <div class="navbar-header">
                    <a class="navbar-brand" href="#">Hands On Lab</a>
                </div>
                <ul class="nav navbar-nav">
                    <li><a href="./ongoing.php">Ongoing Projects</a></li>
                    <li><a href="./closed.php">Closed Projects</a></li>
                </ul>
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <form class="navbar-form navbar-right" action="/action_page.php">
                            <div class="input-group">
                                <input type="text" id="searchfor" class="form-control" placeholder="Search" name="search">
                                <div class="input-group-btn">
                                    <button class="btn btn-default" type="submit">
                                        <i class="glyphicon glyphicon-search"></i>
                                    </button>
                                </div>
                            </div>
                        </form>
                    </li>
                    <li class="nav dropdown">
                        <a class= "nav-link drowpdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-log-in"></span> Login</a>
                        <div class="dropdown-menu" style="padding: 15px; padding-bottom: 10px;">
                            <form class="form-horizontal" method="post" accept-charset="UTF-8">
                                <input class="form-control login" type="email" name="email" placeholder="Email.."><br>
                                <input class="form-control login" type="password" name="pswd" placeholder="Password.."><br>
                                <input class="btn btn-primary" style="background-color:black" type="submit" name="submit" value="Login">
                                <br>
                                <a href="./registration.php">Sign up Here</a>
                            </form>
                        </div>
                    </li>
                </ul>
            </div>
        </nav>
 </body>
 <script>
     $(document).ready(function() {
        $(function() {
        $("input").on("input.highlight", function() {
            // Determine specified search term
            var searchTerm = $(this).val();
            // Highlight search term inside a specific context
            $("#context").unmark().mark(searchTerm);
        }).trigger("input.highlight").focus();
        });
     })
    </script>
 </html>
        

【问题讨论】:

  • 定义“不起作用”。完全加载不出来?不倒?看起来不对劲?另外,您似乎已经发布了代码的工作(硬编码)版本?
  • 是的,这是新的,但这是通过“包含”被拉入另一个页面的代码,但我想通了。需要删除标题部分。

标签: php include navbar


【解决方案1】:

尝试通过将ini_set('display_errors', 1); 放在发生错误的文件开头来调试PHP。

在您的情况下,很可能会出现No such file or directory in .../dropdown.php on line 110 之类的错误,因为 PHP 找不到您要包含的文件。

【讨论】:

  • 想通了,我只需要删除标题部分。当我在另一个页面上使用包含时,它会拉出这个标题并将其放在正文中导致问题。
猜你喜欢
  • 1970-01-01
  • 2015-03-16
  • 2015-07-02
  • 2018-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-16
  • 1970-01-01
相关资源
最近更新 更多