Bootstrap选项卡 - Typeerror .tab不是一个函数

时间:2016-04-24 13:29:02

标签: javascript html twitter-bootstrap tabs

我正在尝试以编程方式更改标签,如下所示:

<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不是函数

有什么想法吗?

编辑:

可以肯定的是,我还根据bootstrap网站在我的_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>

1 个答案:

答案 0 :(得分:1)

你正在使用哪种浏览器?完整性属性似乎尚未完全整合(see the mozilla compatibility list

我尝试了没有cdn链接的代码并且运行得很好。另一方面,使用完整性属性,我得到了与你一样的错误,但重新加载后它工作(尝试使用chrome 49和firefox 45.0.2)