我有以下的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事件,但是如果我想通过网址更改选项卡,那么它不会工作,除非他们单击一个选项卡。那么,我该如何获得它来倾听点击,并听取当前网址中是否有值?