我正在使用codeigniter而且我遇到了与该主题相同的问题:
Link to specific tab Bootstrap
我正在尝试如下,但没有成功:
<ul class="nav nav-pills nav-stacked">
<li class="<?php echo ($acao == 'listar') ? 'active' : ''; ?>">
<a href="#mytab1" data-toggle="tab">
<i class="fa fa-cogs"></i> Name Link My tab 1
</a>
</li>
<li class="<?php echo ($acao == 'cadastro') ? 'active' : ''; ?>">
<a href="#mytab2" data-toggle="tab">
<i class="fa fa-folder-open"></i> Name Link My tab 2
</a>
</li>
<li class="<?php echo ($acao == 'tipos') ? 'active' : ''; ?>">
<a href="#mytab2" data-toggle="tab">
<i class="fa fa-cogs"></i> Name Link My tab 3
</a>
</li>
</ul>
在页脚中:
<script type="text/javascript">
$(function() {
// Javascript to enable link to tab
var hash = document.location.hash;
if (hash) {
console.log(hash);
$('.nav-stacked a[href='+hash+']').tab('show');
}
// Change hash for page-reload
$('a[data-toggle="tab"]').on('show.bs.tab', function (e) {
window.location.hash = e.target.hash;
});
});
</script>
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="<?php echo site_url('assets/js/jquery-1.10.2.min.js'); ?>"></script>
<script src="<?php echo site_url('assets/js/jquery-migrate-1.2.1.min.js'); ?>"></script>
<script src="<?php echo site_url('assets/js/jquery-ui.js'); ?>"></script>
我也尝试将该类改为:
$('.nav-pills a[href='+hash+']').tab('show');
并放入头部javascript,但它不起作用,我错了?
答案 0 :(得分:0)
尝试
$(&#39; .nav-stacked a [href =&#39; + hash +&#39;]&#39;)。show();