Bootstrap 3选项卡无法正常工作

时间:2016-05-03 14:57:21

标签: twitter-bootstrap-3 tabs

开发一个网站,根据我的梦想应该有几个标签, 但事情是,当我点击一个标签时,它只显示标题标签之间的内容,而不是P标签, 这是我的代码。请帮助我实现我的梦想:-D

<div class="panel panel-default">
  <div class="panel-body tabs">
    <ul class="nav nav-pills" data-tabs="tabs">
      <li class="active"><a href="#tab1" data-toggle="tab1">Tab1</a>
      </li>
      <li><a href="#tab2" data-toggle="tab">Tab2</a>
      </li>
      <li><a href="#tab3" data-toggle="tab">Tab3</a>
      </li>
    </ul>
    <div class="tab-content">
      <div class="tab-pane fade in active" id="tab1">
        <h4>Heading1</h4>
        <p>text</p>
      </div>
      <div class="tab-pane fade" id="tab2">
        <h4>Heading2</h4> 
        <p>text</p>
      </div>
      <div class="tab-pane fade" id="tab3">
        <h4>Heading3</h4>
        <p>text</p>
      </div>
    </div>
  </div>
</div>

2 个答案:

答案 0 :(得分:1)

我认为你错过了jQuery链接。 代码有效。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

<div class="panel panel-default">
  <div class="panel-body tabs">
    <ul class="nav nav-pills" data-tabs="tabs">
      <li class="active"><a href="#tab1" data-toggle="tab">Tab1</a>
      </li>
      <li><a href="#tab2" data-toggle="tab">Tab2</a>
      </li>
      <li><a href="#tab3" data-toggle="tab">Tab3</a>
      </li>
    </ul>
    <div class="tab-content">
      <div class="tab-pane fade in active" id="tab1">
        <h4>Heading1</h4>
        <p>text in p</p>
      </div>
      <div class="tab-pane fade" id="tab2">
        <h4>Heading2</h4> 
        <p>text in p</p>
      </div>
      <div class="tab-pane fade" id="tab3">
        <h4>Heading3</h4>
        <p>text in p</p>
      </div>
    </div>
  </div>
</div>

输出:

enter image description here enter image description here

答案 1 :(得分:0)

您需要通过JavaScript启用可列表标签

<script>
    $('.nav-pills a').click(function (e) {
      e.preventDefault()
      $(this).tab('show')
    })
</script>