切换活动引导标签?

时间:2017-11-14 17:48:16

标签: html twitter-bootstrap

据我所知,我已经完全按照w3示例关于引导标签(https://www.w3schools.com/bootstrap/bootstrap_tabs_pills.asp)。但是,使用以下代码时,标签在单击时不会发生变化。显示的唯一选项卡是活动选项卡。我对bootstrap并不是很熟悉,所以我想解决方案可能很简单。

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Login</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="stylesheet" href="css/login.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

  <script src="js/login.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

</head>

<body>
  <div class="container">
    <!-- <div id="tabs" class="container"> -->
      <ul class="nav nav-tabs">
        <li class="active">
          <a data-toggle="tab" href="#student">Student</a>
        </li>

        <li>
          <a data-toggle="tab" href="#employee">Employee</a>
        </li>

        <li>
          <a data-toggle="tab" href="#admin">Admin</a>
        </li>
      </ul>

      <div class="tab-content">
        <div id="student" class="tab-pane fade in active">
          <h1>TEST</h1>
        </div>
        <div id="employee" class="tab-pane fade">
          <h1>TEST2</h1>
        </div>
        <div id="admin" class="tab-pane fade">
          <h1>TEST3</h1>
        </div>
      </div>

    <!-- </div> -->
  </div>

</body>
</html>

1 个答案:

答案 0 :(得分:1)

W3的例子也不起作用!试试这个

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Login</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="stylesheet" href="css/login.css">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

        <script src="js/login.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

    </head>

    <body>
        <div class="container">
            <!-- Nav tabs -->
            <ul class="nav nav-tabs" role="tablist">
                <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Home</a></li>
                <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li>
                <li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Messages</a></li>
                <li role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Settings</a></li>
            </ul>

            <!-- Tab panes -->
            <div class="tab-content">
                <div role="tabpanel" class="tab-pane active" id="home">
                    TEST 1
                </div>
                <div role="tabpanel" class="tab-pane" id="profile">
                    TEST 2
                </div>
                <div role="tabpanel" class="tab-pane" id="messages">
                    TEST 3
                </div>
                <div role="tabpanel" class="tab-pane" id="settings">
                    TEST 4
                </div>
            </div>

        </div>
    </body>
</html>

并查看:https://getbootstrap.com/docs/3.3/javascript/#tabs了解更多信息

修改

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

此行必须在bootstrap.min.js之前执行,如下所示:

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>