我目前使用Zurb Foundation Tabs爲小型項目。這些標籤工作的很好,但是當我嘗試將URL定位到特定的標籤頁時,我遇到了一堵牆。我搜索並找到了一個獲取此方法的方法,但修改並將其應用於我的示例時,該方法無效。我收到錯誤:「無法識別的表達式::第n個孩子」。我如何正確鏈接到Foundation 5中的特定標籤? DEMOURL目標鏈接選項卡 - Zurb基礎選項卡
JS/JQuery的網址的目標
<script>
window.navigateTab = function (event) {
var url = $(event.target).attr('href');
var target = url.split('#')[1];
if (target.substr(0, 5) == 'panel') {
var state = {
tab: target.substr(5)
};
selectTab("tabs_edit", state.tab); //<-- change the tab
history.pushState(state, null, url); //<-- change the url
event.preventDefault();
}
}
window.onpopstate = function (event) {
if (event.state != null) {
selectTab("tabs_edit", event.state.tab); //<-- change the tab
}
};
function selectTab(id, tab) {
// activate only the right tab:
var tab = $("#" + id + "> dl > dd:nth-child(" + tab + ")");
console.log(tab);
var a = $("a", tab);
target = $('#' + a.attr("href").split('#')[1]);
siblings = tab.siblings();
settings = tab.closest('[data-tab]').data('tab-init');
tab.addClass(settings.active_class);
siblings.removeClass(settings.active_class);
target.siblings().removeClass(settings.active_class).end().addClass(settings.active_class);
}
$('#menu a').on("click", navigateTab);
$(document).foundation();
</script>
HTML
//Target an specific tab:
<ul id="menu" class="dropdown">
<li><a href="#panel1a">Tab 1</a></li>
<li><a href="#panel2a">Tab 2</a></li>
<li><a href="#panel3a">Tab 3</a></li>
</ul>
//Actual Tabs
<dl id="tabs_edit" class="tabs vertical" data-tab>
<dd class="active"><a href="#panel1a" onclick="navigateTab(event)">Tab 1</a></dd>
<dd><a href="#panel2a" href="#panel2a" onclick="navigateTab(event)">Tab 2</a></dd>
<dd><a href="#panel3a" href="#panel3a" onclick="navigateTab(event)">Tab 3</a></dd>
<dd><a href="#panel4a" href="#panel4a" onclick="navigateTab(event)">Tab 4</a></dd>
</dl>
<div class="tabs-content vertical">
<div class="content active" id="panel1a">
<p>Panel 1 content goes here.</p>
</div>
<div class="content" id="panel2a">
<p>Panel 2 content goes here.</p>
</div>
<div class="content" id="panel3a">
<p>Panel 3 content goes here.</p>
</div>
<div class="content" id="panel4a">
<p>Panel 4 content goes here.</p>
</div>
</div>
可能擴展到'$( 'dl.tabs DD一')加($('ul.tabs禮a'))。add($('ol.tabs li a'))' –