我有它的標籤頁,你這個jQuery腳本打開jQuery的標籤與URL
http://www.sohtanaka.com/web-design/simple-tabs-w-css-jquery/
我希望能夠使接片3是第一個開放的,當用戶進入到URL http://mysite.com/about.php#tab3
這可能嗎?
我有它的標籤頁,你這個jQuery腳本打開jQuery的標籤與URL
http://www.sohtanaka.com/web-design/simple-tabs-w-css-jquery/
我希望能夠使接片3是第一個開放的,當用戶進入到URL http://mysite.com/about.php#tab3
這可能嗎?
據例如,你可以用這種方式modifi它:
$(function() {
$(".tab_content").hide(); //Hide all content
//On Click Event (left standart)
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
});
// here we are looking for our tab header
hash = window.location.hash;
elements = $('a[href="' + hash + '"]');
if (elements.length === 0) {
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content
} else {
elements.click();
}
});
Working example is here。要小心 - 散列硬編碼那裏,因爲我不知道如何通過它來測試框架:(
是的,你可以做到這一點。您將需要一些代碼來抓取url並觸發適當的選項卡。
或者你可以檢查出jQuery的工具選項卡(http://flowplayer.org/tools/demos/tabs/) 或jQuery UI的標籤(http://jqueryui.com/demos/tabs/)
這些都具有該功能(和一噸的其他選項)已經內置
我沒有測試這一點,但你應該能夠從URL獲得哈希:
var hash= window.location.hash;
然後用請求的哈希鏈接抓取鏈接元素,並模擬點擊它
$("a[href='"+hash+"']").click();
工作就像一個魅力! – 2011-06-30 22:18:13
幫助我謝謝! – Heihachi 2013-03-26 10:24:35