【问题标题】:Bootstrap tabs - Typeerror .tab is not a function引导选项卡 - Typeerror .tab 不是函数
【发布时间】:2016-08-17 20:27:20
【问题描述】:

我正在尝试以编程方式更改选项卡,如下所示:

<ul class="nav nav-tabs" role="tablist">
    <li class="active"><a href="#step1" data-toggle="tab" >Step 1</a></li>
    <li><a href="#step2" data-toggle="tab" >Step 2</a></li>
</ul>

<div class="tab-content" id="tabs">
    <div id="step1" class="tab-pane fade in active">
    </div>
    <div id="step2" class="tab-pane fade">
    </div>
</div>

JS(在一定条件下):

$('a[href="#step2"]').tab('show');

这不起作用,我收到错误:TypeError: $(...).tab is not a function

有什么想法吗?

编辑:

可以肯定的是,根据引导网站,我还在我的 _Layout 文件中包含以下内容:

<!-- 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>

【问题讨论】:

  • 你有没有加载bootstrap JS文件

标签: javascript html twitter-bootstrap tabs


【解决方案1】:

您使用的是哪个浏览器?完整性属性似乎还没有完全集成 (see the mozilla compatibility list)

我在没有 CDN 链接的情况下尝试了这段代码,并且工作得很好。另一方面,使用完整性属性,我一开始遇到了和你一样的错误,但重新加载后它起作用了(在 chrome 49 和 firefox 45.0.2 上试过)

【讨论】:

  • 您是否尝试过使用自己的引导程序版本,以防万一?否则,因为它对我来说是这样工作的,我猜错误会在你的代码中的其他地方,你能提供 $('a[href="#step2"]').tab('show'); 的条件吗? ?
猜你喜欢
  • 1970-01-01
  • 2018-01-11
  • 2013-08-15
  • 2018-09-03
  • 2015-05-15
  • 2013-11-18
  • 2012-10-23
  • 1970-01-01
相关资源
最近更新 更多