0
我为我的引导选项卡使用下面的代码,以便使url中的选项卡的#名称,因为我想要在完成某些发布操作后重定向到特定的选项卡,它工作正常。一个href链接在选项卡内没有做任何事
但是,自从我开始使用代码以来,所有其他链接都停止了任何操作,它不会打开页面或显示错误,一点都没有。
这里是我的代码:
$(function() {
var gotoHashTab = function (customHash) {
var hash = customHash || location.hash;
var hashPieces = hash.split('?'),
activeTab = $('[href=' + hashPieces[0] + ']');
activeTab && activeTab.tab('show');
}
// onready go to the tab requested in the page hash
gotoHashTab();
// when the nav item is selected update the page hash
$('.nav a').on('shown.bs.tab', function (e) {
window.location.hash = e.target.hash
//location.hash = $(e.target).attr('href').substr(1);
scrollTo(0,0);
})
// when a link within a tab is clicked, go to the tab requested
$('.tab-pane a').click(function (event) {
if (event.target.hash) {
e.preventDefault();
gotoHashTab(event.target.hash);
}
})
$('.tab-pane a').on('click', function(e){
e.preventDefault()
})
});
我注意到其他一些问题,e.preventDefault()
可能会导致这种情况,但是当我评论这些时什么都没有发生。
如何重写代码以保持功能,但使这些正常的链接再次工作?
activeTab = $( '[HREF =' + hashPieces [0] + ']');编辑到: activeTab = $('。tab-pane [href ='+ hashPieces [0] +']'); – Christina