我使用的標籤簡單jQuery腳本:jQuery選項卡:如何創建指向特定選項卡的鏈接?
的JS:
$(document).ready(function() {
$(".tab-content").hide();
$("ul.tabs li:first").addClass("active").show();
$(".tab-content:first").show();
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active");
$(this).addClass("active");
$(".tab-content").hide();
var activeTab = $(this).find("a").attr("href");
$(activeTab).show();
return false;
});
});
的HTML(爲的index.html):
<div id="tabs">
<ul class="tabs">
<li><a href="#tabs-voters">Top Voters</a></li>
<li><a href="#tabs-commenters">Top Commenters</a></li>
</ul>
<div id="tabs-voters" class="tab-content">
<p id="h1-01">Tab content</p>
<p>Some content</p>
</div>
<div id="tabs-commenters" class="tab-content">
<h2 id="h-02">Tab content</h2>
<p>Some content</p>
<h2 id="h-03">Tab content</h2>
<p>Some content</p>
</div>
</div>
我需要做的是什麼創建一個到index.html#h-02,index.html#h-03等的工作鏈接,但這些簡單的鏈接不起作用,因爲該選項卡默認爲隱藏。是否有可能修改JS,所以我可以鏈接到打開index.html時隱藏的標籤中的書籤?有人能指引我朝着正確的方向嗎?
非常感謝! :)
這將與問題中提供的URL一起使用。 +1 – user113716 2010-08-30 14:17:05
謝謝!我想這聽起來像我正在尋找的。不幸的是,我更多的是一個設計師/ HTML + CSS的人,所以我沒有絲毫的線索如何在現實生活中實現這一點。非常感謝你或者有人可以更詳細地解釋這個問題(或者幫助完成最終腳本)。 – klavina 2010-08-30 14:27:09
@klavina - 發佈〜2行代碼應該是你需要的!事實上,只需將以下代碼行添加到文檔就緒處理程序的末尾即可:「$(window.location.hash).click();' - 無論如何,我會複製代碼到我的答案提供一個完整的代碼片段。 – 2010-08-30 14:29:29