bootstrap 导航栏无法与 bootstrap 4.0.0-alpha.2 一起使用

bootstrap Navbar not working with bootstrap 4.0.0-alpha.2

bootstrap 导航栏无法使用 bootstrap 4.0.0-alpha.2 并且滚动 spy.I 试图用 [=23 替换脚本和 css 文件=] 3.3.7 工作正常,但在这个版本中,导航栏的样式和间谍滚动都不起作用

<!DOCTYPE html>
<html lang="en">
  <head>

    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <meta http-equiv="x-ua-compatible" content="ie=edge"> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous">

    <style type="text/css">

      body{

        position:relative;

      }

      #home{

        margin-top:50px;

      }

      #home {padding-top:50px;height:500px;color: #fff; background-color: green;}
      #one {padding-top:50px;height:500px;color: #fff; background-color: #1E88E5;}
      #two {padding-top:50px;height:500px;color: #fff; background-color: #673ab7;}
      #three {padding-top:50px;height:500px;color: #fff; background-color: #ff9800;}
      #two1 {padding-top:50px;height:500px;color: #fff; background-color: #00bcd4;}
      #two2 {padding-top:50px;height:500px;color: #fff; background-color: #009688;}

    </style>



  </head>
  <body data-scroll="spy" data-target="#myNavbar" data-offset="10">

    <nav  class="navbar navbar-inverse navbar-fixed-top" id="myNavbar">

      <div class="container-fluid">

        <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 href="#" class="navbar-brand">WebSiteName</a>

        </div>

        <div class="collapse navbar-collapse" id="myNavbar"> 

          <ul class=" nav navbar-nav" >

            <li class="active"><a href="#home">Home</a></li>

            <li><a href="#one">Section 1</a></li>

            <li class="dropdown"><a  class="dropdown-toggle" data-toggle="dropdown" href="#">Section 2<span class="caret"></span></a>

              <ul class="dropdown-menu" >

                <li><a href="two1">Section 2-1</a></li>

                <li><a href="two2">Section 2-2</a></li>

                <li><a href="two3">Section 2-3</a></li>

              </ul>

            </li>

            <li><a href="#three">Section 3</a></li>

          </ul>
        </div>
      </div>

    </nav>




    <div id="home" class="container-fluid">

      <h1>Home</h1>

      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>

    </div>


    <div id="one" class="container-fluid">

      <h1>One</h1>

      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>

    </div>                                                             



    <div id="two" class="container-fluid">

      <h1>two</h1>

      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>


    </div>



    <div id="three" class="container-fluid">

      <h1>Three</h1>

      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>


    </div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.3.4/js/tether.min.js" ></script>

    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js" integrity="sha384-vZ2WRJMwsjRMW/8U7i6PWi6AlO1L79snBrmgiDpgIWJ82z8eA5lenwvxbMV1PAh7" crossorigin="anonymous"></script> 

    <script type="text/javascript">

      $("body").scrollspy({target:"#myNavbar"});

    </script>

  </body>
</html>

更新 HTML accordingly for the new Bootstrap 4 navbar..

http://codeply.com/go/yPEQsECngS

我 运行 你的 3.x 代码通过这个 Bootstrap 4 upgrade tool 和 scrollspy 按预期工作。另请记住,Bootstrap 4 目前处于 ALPHA 阶段,因此它会发生变化。