我有以下的jQuery代碼,允許我使用製表符,以在內容/ div之間回退和第四。我的問題是使用下面的代碼,我怎麼能根據url中的變量加載最初的選項卡?所以,如果我去默認TAB2負載somesite.com/page.php#tab2的則不用TAB1裝載:jquery - 通過網址選擇標籤
$('.tabcontent > div').hide();
$('.tabcontent > div:first-child').show();
$('.tabs > li:first-child').addClass('selected');
$('.tabs > li a').click(function() {
var tab_id = $(this).attr('href');
$(tab_id).parent().children().hide();
$(tab_id).fadeIn();
$(this).parent().parent().children().removeClass('selected');
$(this).parent().addClass('selected');
return false;
});
編輯
只是要注意這個代碼是一個click事件,但是如果我想通過網址更改選項卡,那麼它不會工作,除非他們單擊一個選項卡。那麼,我該如何獲得它來傾聽點擊,並聽取當前網址中是否有值?