下一个选项卡显示内容但不跟随选项卡

时间:2015-11-19 20:52:50

标签: javascript jquery html twitter-bootstrap bootstrap-tabs

我有两个表分隔两个标签。 积极和无效

假设我单击活动标签中的下一个按钮。 “非活动”选项卡的内容显示,但活动选项卡仍为“活动”选项卡。我错过了什么吗?

让我们说他们相应的ID是#Active和#Inactive。这是下一个按钮的代码:

<a href=#Inactive data-toggle="tab" aria-expanded="false">
    <button class="btn next">Next</button>
</a>

1 个答案:

答案 0 :(得分:1)

从您的代码中我猜您正在使用 bootstrap tabs ,因此您应该在JS代码中添加click事件以检测点击next按钮并将您转到第二个标签。

希望这有帮助。

$('.next').click(function () {
    $('#myTabs a[href="#inactive"]').tab('show');
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>

<div class='container'>
  
  <!-- Nav tabs --><br>
  <ul class="nav nav-tabs" id='myTabs' role="tablist">
    <li role="presentation" class="active"><a href="#acitve" aria-controls="acitve" role="tab" data-toggle="tab">Active</a></li>
    <li role="presentation"><a href="#inactive" aria-controls="inactive" role="tab" data-toggle="tab">Inactive</a></li>
  </ul>

  <!-- Tab panes -->
  <div class="tab-content">
    <div role="tabpanel" class="tab-pane active" id="acitve">
      table 1 
      </br> 
      <button class="btn next">Next</button>
    </div>
    <div role="tabpanel" class="tab-pane" id="inactive">
      table 2
    </div>
  </div>

</div>

相关问题