2011-03-30 67 views

回答

4

据例如,你可以用这种方式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。要小心 - 散列硬编码那里,因为我不知道如何通过它来测试框架:(

+0

工作就像一个魅力! – 2011-06-30 22:18:13

+0

帮助我谢谢! – Heihachi 2013-03-26 10:24:35

0

是的,你可以做到这一点。您将需要一些代码来抓取url并触发适当的选项卡。

或者你可以检查出jQuery的工具选项卡(http://flowplayer.org/tools/demos/tabs/) 或jQuery UI的标签(http://jqueryui.com/demos/tabs/)

这些都具有该功能(和一吨的其他选项)已经内置

2

我没有测试这一点,但你应该能够从URL获得哈希:

var hash= window.location.hash; 

然后用请求的哈希链接抓取链接元素,并模拟点击它

$("a[href='"+hash+"']").click();