Twitter Bootstrap - 标签 - URL 不会改变 [英] Twitter Bootstrap - Tabs - URL doesn't change
本文介绍了Twitter Bootstrap - 标签 - URL 不会改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Twitter Bootstrap 及其标签".
I'm using Twitter Bootstrap and its "tabs".
我有以下代码:
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#add">add</a></li>
<li><a data-toggle="tab" href="#edit" >edit</a></li>
<li><a data-toggle="tab" href="#delete" >delete</a></li>
</ul>
选项卡工作正常,但 URL 中没有添加 #add、#edit、#delete.
The tabs work properly, but the in the URL is not added the #add, #edit, #delete.
当我删除 data-toggle
时,URL 会发生变化,但选项卡不起作用.
When I remove data-toggle
the URL changes, but the tabs don't work.
对此有什么解决方案吗?
Any solutions for this?
推荐答案
试试这个代码.它将标签 href 添加到 url + 根据页面加载时的哈希打开标签:
Try this code. It adds tab href to url + opens tab based on hash on page load:
$(function(){
var hash = window.location.hash;
hash && $('ul.nav a[href="' + hash + '"]').tab('show');
$('.nav-tabs a').click(function (e) {
$(this).tab('show');
var scrollmem = $('body').scrollTop() || $('html').scrollTop();
window.location.hash = this.hash;
$('html,body').scrollTop(scrollmem);
});
});
这篇关于Twitter Bootstrap - 标签 - URL 不会改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文