好的我在发布之前搜索论坛&找到很多解决方案不幸的是没有一个人在为我工作。我正在使用最新的bootsrap v3.3.5&当我试图改变我的标签时,页面跳到顶部&选项卡面板中的内容会下降。
<div id="featured-tabs">
<!-- Nav tabs -->
<ul class="list-inline" role="tablist">
<li role="presentation" class="active"><a href="#residential" aria-controls="residential" role="tab" data-toggle="tab" class="btn btn-theme-primary btn-lg">Residential</a></li>
<li role="presentation"><a href="#commercial" aria-controls="commercial" role="tab" data-toggle="tab" class="btn btn-theme-secondary btn-lg">Commercial</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane fade in active" id="residential">
....content here
</div>
<div role="tabpanel" class="tab-pane fade" id="commercial">
....content here
</div>
</div>
</div>
&安培;这是我的js:
$('#featured-tabs ul.list-inline li a').click(function (e) {
e.preventDefault();
$(this).tab('show');
history.pushState( null, null, $(this).attr('href') );
})
那么如何才能解决最新Bootstrap版本的页面跳转问题?
答案 0 :(得分:0)
在关闭标签之前检查你是否有jquery和bootstrap.js文件
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
你可以在没有javascript的情况下使用它,就像在bootstrap中所说的那样 http://getbootstrap.com/javascript/#tabs
只是:
<div>
<!-- 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">...</div>
<div role="tabpanel" class="tab-pane" id="profile">...</div>
<div role="tabpanel" class="tab-pane" id="messages">...</div>
<div role="tabpanel" class="tab-pane" id="settings">...</div>
</div>
</div>
答案 1 :(得分:0)
尝试使用:
$('#featured-tabs ul.list-inline li a').click(function (e) {
e.preventDefault();
e.stopImmediatePropagation();
$(this).tab('show');
history.pushState( null, null, $(this).attr('href') );
})