这是我之前发布的问题的后续,但我无法让它工作..
我正在尝试在一页上使用多组选项卡(jQuery)。
这是我拥有的一组标签的代码,效果很好:
$('div.tabs div.tab').hide();
$('div.tabs div:first').show();
$('div.tabs ul.htabs li:first a').addClass('current');
$('div.tabs ul.htabs li a').click(function(){
$('div.tabs ul.htabs li a').removeClass('current');
$(this).addClass('current');
var currentTab = $(this).attr('href');
$('div.tabs div.tab').hide();
$(currentTab).show();
return false;
});
为了在页面上使用多个集合,我为每个选项卡集分配了#id,并尝试通过以下方式实现这一点:
$.each(['#tabs-1', '#tabs-2', '#tabs-3' ], function(id) {
$(id + 'div.tab').hide();
$(id + 'div:first').show();
$(id + 'ul.htabs li:first a').addClass('current');
$(id + 'ul.htabs li a').click(function(){
$(id + 'ul.htabs li a').removeClass('current');
$(this).addClass('current');
var currentTab = $(this).attr('href');
$(id + 'div.tab').hide();
$(currentTab).show();
return false;
});
});
显然我在这里做错了,但作为一个 jQuery 新手,我很难过!