根据url中的#hash激活标签

假设我有一个如下所示的URL …如何激活正确的标签?

http://domain.com/safety.php#tabOne

inheritance我的HTML:

 

和我的观察:

 $('.tabset>li>a').click(function(){ var $tab; $(this).closest('.tabset').find('>li>a.active').removeClass('active'); $(this).addClass('active'); $tab = $($(this).attr('href')); $tab.siblings().hide(); $tab.find('>div').show(); $tab.fadeIn(); return false; }); $('#tabbedContent').each(function(){ $(this).find(':first-child').fadeIn(); }); 

 if(location.hash) { $('#tabbedContent').each(function(){ $(this).find("section#" + location.hash.substr(1)).fadeIn(); }); } else { $('#tabbedContent').each(function(){ $(this).find(':first-child').fadeIn(); }); } 

使用location.hash :)! 您可能需要先删除#