我正试图实现我的网站的登录和注册形式作为一个引导模式,但在点击导航栏内的链接后,模式根本没有出现。我以前在这个话题上遇到过一些类似的问题,但似乎没有一个解决方案对我有用。JQuery包含在内,所以我不知道是什么原因导致modal害羞地出现。有人能帮忙吗?代码如下:


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- CSRF Token -->
        <meta name="csrf-token" content="Mc8MyxbLVQ93MY1dMlbE6y9NXzlTiVrVB80P0lYl">
        <link rel="stylesheet" href="http://mypage.me/css/app.css">

        <title>MyPage</title>
         <!-- jQuery first, then Popper.js, then Bootstrap JS -->
         <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-
    q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
         <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
    integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
    crossorigin="anonymous"></script>
         <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
    integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
    crossorigin="anonymous"></script>
         <style>
          body, html {
            height: 100%;
            margin: 0;
          }

          .bg {
            /* The image used */
            background-image: url("/images/ukay3.jpg");

            /* Full height */
            height: 100%;

            /* Center and scale the image nicely */
            background-position: center;
            background-repeat: no-repeat;
            background-size: cover;
          }

          .navbar { margin-bottom: 0 !important; }
          </style>
        </head>
    <body>
      <a class="nav-link" href="#" data-toggle="modal" data-target="#loginModal">Logi</a>

    <!-- Old Navbar -->
    <nav class="navbar navbar-inverse">
    <div class="container-fluid">
    <!-- Section: Logo and collapse button -->
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
      <a style="display:block; margin:7px; margin-right:20px" href="/ " class="pull-left"><img
    src="/images/logosmall.png" alt="Not found!"></a>
    </div><!-- End Section: Logo and collapse button -->
      <!-- Section: Collapsible part of Navbar -->
     <div class="collapse navbar-collapse" id="myNavbar">
        <ul class="nav navbar-nav">
            <li><a href="/">Home</a></li>
            <li><a href="/posts">Market</a></li>
            <li class="dropdown">
              <a class="dropdown-toggle" data-toggle="dropdown" href="/about">About<span class="caret">
     </span></a>
              <ul class="dropdown-menu">
                <li><a href="/about">Page1</a></li>
                <li><a href="/about">Page2</a></li>
                <li><a href="/about">Page3</a></li>
              </ul>
            </li>
            <!--<li><a href="/about">About</a></li>-->
            <li><a href="/services">Services</a></li>
            <li><a href="/contact">Contact</a></li>
          </ul>
    <!-- Section: Right side of Navbar -->
    <!-- Right Side Of Navbar -->
    <ul class="nav navbar-nav navbar-right">
        <!-- Authentication Links -->
                    <li class="nav-item">
                <a class="nav-link" href="#" data-toggle="modal" data-target="#loginModal"><span
    class="glyphicon glyphicon-log-in"></span> Login</a>
            </li>
                            <li class="nav-item">
                    <a class="nav-link" href="http://mypage.me/register"><span class="glyphicon
     glyphicon-user"></span> Sign Up</a>
                </li>
                        </ul><!-- Right Side of Navbar --><!-- End Section: Right side of Navbar -->
    </div><!-- End Section: Collapsible part of Navbar -->
      </div>
    </nav>

    <!-- Login Modal -->
    <div class="modal fade" id="loginModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>Some text in the modal.</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
    </div>
    <!-- Modal End -->      <div class="bg"></div>
      <div class="container">

            <div class="jumbotron text-center">
        <h1>Welcome to MyPage.com</h1>
    </div>
      </div>

    </body>
    </html>

最佳答案

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- CSRF Token -->
        <meta name="csrf-token" content="Mc8MyxbLVQ93MY1dMlbE6y9NXzlTiVrVB80P0lYl">
        <link rel="stylesheet" href="http://mypage.me/css/app.css">

        <title>MyPage</title>
         <!-- jQuery first, then Popper.js, then Bootstrap JS -->
         <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-
    q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
         <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
    integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
    crossorigin="anonymous"></script>
         <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
    integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
    crossorigin="anonymous"></script>
         <style>
          body, html {
            height: 100%;
            margin: 0;
          }

          .bg {
            /* The image used */
            background-image: url("/images/ukay3.jpg");

            /* Full height */
            height: 100%;

            /* Center and scale the image nicely */
            background-position: center;
            background-repeat: no-repeat;
            background-size: cover;
          }

          .navbar { margin-bottom: 0 !important; }
          </style>
        </head>
    <body>
      <a class="nav-link" href="#" data-toggle="modal" data-target="#loginModal">Logi</a>

    <!-- Old Navbar -->
    <nav class="navbar navbar-inverse">
    <div class="container-fluid">
    <!-- Section: Logo and collapse button -->
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
      <a style="display:block; margin:7px; margin-right:20px" href="/ " class="pull-left"><img
    src="/images/logosmall.png" alt="Not found!"></a>
    </div><!-- End Section: Logo and collapse button -->
      <!-- Section: Collapsible part of Navbar -->
     <div class="collapse navbar-collapse" id="myNavbar">
        <ul class="nav navbar-nav">
            <li><a href="/">Home</a></li>
            <li><a href="/posts">Market</a></li>
            <li class="dropdown">
              <a class="dropdown-toggle" data-toggle="dropdown" href="/about">About<span class="caret">
     </span></a>
              <ul class="dropdown-menu">
                <li><a href="/about">Page1</a></li>
                <li><a href="/about">Page2</a></li>
                <li><a href="/about">Page3</a></li>
              </ul>
            </li>
            <!--<li><a href="/about">About</a></li>-->
            <li><a href="/services">Services</a></li>
            <li><a href="/contact">Contact</a></li>
          </ul>
    <!-- Section: Right side of Navbar -->
    <!-- Right Side Of Navbar -->
    <ul class="nav navbar-nav navbar-right">
        <!-- Authentication Links -->
                    <li class="nav-item">
                <a class="nav-link" href="#loginModal" data-toggle="modal" data-target="#loginModal"><span
    class="glyphicon glyphicon-log-in"></span> Login</a>
            </li>
                            <li class="nav-item">
                    <a class="nav-link" href="http://mypage.me/register"><span class="glyphicon
     glyphicon-user"></span> Sign Up</a>
                </li>
                        </ul><!-- Right Side of Navbar --><!-- End Section: Right side of Navbar -->
    </div><!-- End Section: Collapsible part of Navbar -->
      </div>
    </nav>

    <!-- Login Modal -->
    <div class="modal fade" id="loginModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>Some text in the modal.</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
    </div>
    <!-- Modal End -->      <div class="bg"></div>
      <div class="container">

            <div class="jumbotron text-center">
        <h1>Welcome to MyPage.com</h1>
    </div>
      </div>

    </body>
    </html>

10-07 21:51