bootbox 正在停止下拉菜单工作

bootbox is stopping dropdown-menu to work

我有 asp.net 使用引导箱的核心 MVC。 我注意到我的下拉菜单不起作用,我尝试了所有方法,例如删除 js 文件和 CSS 文件,然后重新添加它们,但没有成功,直到我删除了 bootbox.js 和 bom!并且下拉菜单工作正常。

这是我的 _Layout.cshtml:

<!DOCTYPE html>
<html lang="ar-sa" dir="rtl">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - POS3</title>

    <script src="~/js/bootbox.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="~/lib/bootstrap/dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="~/css/site.css" />





    @*<script src="~/js/popper.min.js"></script>*@


</head>
<body>
    <header>
        <nav class="navbar navbar-expand-lg navbar-light bg-light">
            <a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">POS<sup>3</sup></a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
                    aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <partial name="_LoginPartial" />

                <ul class="navbar-nav mr-auto">

                    <li class="nav-item active">
                        <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home<span class="sr-only">(current)</span></a>
                    </li>

                    <li class="nav-item">
                        <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
                    </li>

                    <li class="nav-item">
                        <a class="nav-link text-dark" asp-area="" asp-controller="SelectedItems" asp-action="POSMain">POSMain</a>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Products</a>
                        <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
                            <il class="dropdown-item">
                                <a class="dropdown-item" asp-area="" asp-controller="Product" asp-action="Create">Add New Product</a>
                            </il>
                        </ul>                
                      
                    </li>
                    <li class="nav-item dropdown">
                        <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
                            <li><a class="dropdown-item" href="#">Action</a></li>
                            <li><a class="dropdown-item" href="#">Another action</a></li>
                            <li class="dropdown-submenu">
                                <a class="dropdown-item dropdown-toggle" href="#">Submenu</a>
                                <ul class="dropdown-menu">
                                    <li><a class="dropdown-item" href="#">Submenu action</a></li>
                                    <li><a class="dropdown-item" href="#">Another submenu action</a></li>


                                    <li class="dropdown-submenu">
                                        <a class="dropdown-item dropdown-toggle" href="#">Subsubmenu</a>
                                        <ul class="dropdown-menu">
                                            <li><a class="dropdown-item" href="#">Subsubmenu action</a></li>
                                            <li><a class="dropdown-item" href="#">Another subsubmenu action</a></li>
                                        </ul>
                                    </li>
                                    <li class="dropdown-submenu">
                                        <a class="dropdown-item dropdown-toggle" href="#">Second subsubmenu</a>
                                        <ul class="dropdown-menu">
                                            <li><a class="dropdown-item" href="#">Subsubmenu action</a></li>
                                            <li><a class="dropdown-item" href="#">Another subsubmenu action</a></li>
                                        </ul>
                                </ul>

                            </li>
                        </ul>
                    </li>
                    </ul>
                <form class="form-inline my-2 my-lg-0">
                    <input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
                    <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
                </form>
</div>
        </nav>
    </header>
    <div class="container" >
        <main role="main" class="pb-3">
            @RenderBody()
        </main>
    </div>

    <footer class="border-top footer text-muted">
        <div class="container">
            &copy; 2019 - POS3 - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
        </div>
    </footer>
    <script src="~/lib/jquery/dist/jquery-3.3.1.js"></script>
    <script src="~/lib/jquery/dist/jquery.js"></script>
    <script src="~/js/jquery.dataTables.min.js"></script>
    <script src="~/js/DataTables/jquery.dataTables.min.js" defer></script>
    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <script src="~/js/site.js" asp-append-version="true"></script>
    @RenderSection("Scripts", required: false)
    @RenderSection("Menu", required: false)
    @RenderSection("ProductScript", false)
</body>
</html>

我认为 bootbox.js 中有一些东西只是阻止下拉菜单正常工作。

假设您的项目中的其他所有内容都正确构建,您的布局有很多问题需要修复:

  1. 您已经包含 jQuery 好几次了。除一个外,全部删除。
  2. 您加载了两个不同版本的 bootstrap.js,并且顺序不对。
  3. 您在 <head> 中添加了 bootbox.js 作为第一个脚本。 正如我们注意到的 在我们的文档中, Bootbox 需要在 Bootstrap 之后加载(因为它是 Bootstrap 扩展)。

因此,删除冗余并修复脚本顺序,这就是您剩下的内容(我在末尾将脚本隔开,以便您可以看到加载的内容):

<!DOCTYPE html>
<html lang="ar-sa" dir="rtl">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - POS3</title>

    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
    <header>
        <nav class="navbar navbar-expand-lg navbar-light bg-light">
            <a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">POS<sup>3</sup></a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
                    aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <partial name="_LoginPartial" />

                <ul class="navbar-nav mr-auto">

                    <li class="nav-item active">
                        <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home<span class="sr-only">(current)</span></a>
                    </li>

                    <li class="nav-item">
                        <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
                    </li>

                    <li class="nav-item">
                        <a class="nav-link text-dark" asp-area="" asp-controller="SelectedItems" asp-action="POSMain">POSMain</a>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Products</a>
                        <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
                            <il class="dropdown-item">
                                <a class="dropdown-item" asp-area="" asp-controller="Product" asp-action="Create">Add New Product</a>
                            </il>
                        </ul>                

                    </li>
                    <li class="nav-item dropdown">
                        <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
                            <li><a class="dropdown-item" href="#">Action</a></li>
                            <li><a class="dropdown-item" href="#">Another action</a></li>
                            <li class="dropdown-submenu">
                                <a class="dropdown-item dropdown-toggle" href="#">Submenu</a>
                                <ul class="dropdown-menu">
                                    <li><a class="dropdown-item" href="#">Submenu action</a></li>
                                    <li><a class="dropdown-item" href="#">Another submenu action</a></li>


                                    <li class="dropdown-submenu">
                                        <a class="dropdown-item dropdown-toggle" href="#">Subsubmenu</a>
                                        <ul class="dropdown-menu">
                                            <li><a class="dropdown-item" href="#">Subsubmenu action</a></li>
                                            <li><a class="dropdown-item" href="#">Another subsubmenu action</a></li>
                                        </ul>
                                    </li>
                                    <li class="dropdown-submenu">
                                        <a class="dropdown-item dropdown-toggle" href="#">Second subsubmenu</a>
                                        <ul class="dropdown-menu">
                                            <li><a class="dropdown-item" href="#">Subsubmenu action</a></li>
                                            <li><a class="dropdown-item" href="#">Another subsubmenu action</a></li>
                                        </ul>
                                </ul>

                            </li>
                        </ul>
                    </li>
                </ul>
                <form class="form-inline my-2 my-lg-0">
                    <input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
                    <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
                </form>
            </div>
        </nav>
    </header>
    <div class="container" >
        <main role="main" class="pb-3">
            @RenderBody()
        </main>
    </div>

    <footer class="border-top footer text-muted">
        <div class="container">
            &copy; 2019 - POS3 - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
        </div>
    </footer>

    <script src="~/lib/jquery/dist/jquery-3.3.1.js"></script>

    <script src="~/js/jquery.dataTables.min.js"></script>
    <script src="~/js/DataTables/jquery.dataTables.min.js" defer></script>

    <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>

    <script src="~/js/bootbox.min.js"></script>

    <script src="~/js/site.js" asp-append-version="true"></script>

    @RenderSection("Scripts", required: false)
    @RenderSection("Menu", required: false)
    @RenderSection("ProductScript", false)
</body>
</html>