我有 jquery 显示 3 个不同的 div 来显示/隐藏 onclick。一切都按要求工作,只是一旦打开,我就无法隐藏 div。
HTML
<table id="brand-groups">
<tr>
<td id="brandgroupopen-all" class="brand-groups-tab" valign="middle"> ALL BRANDS</td>
<td id="brandgroupopen-fashion" class="brand-groups-tab" valign="middle">POPULAR FASHION BRANDS</td>
<td id="brandgroupopen-beauty" class="brand-groups-tab" valign="middle">POPULAR BEAUTY</td>
</tr>
</table>
<div class="brandgroupoptions">
<div id="brandgroupoptions-all" class="brandgroupoption init-hidden">a</div>
<div id="brandgroupoptions-fashion" class="brandgroupoption init-hidden">fashion</div>
<div id="brandgroupoptions-beauty" class="brandgroupoption init-hidden">beauty</div>
</div>
jQuery
$('.brand-groups-tab').click(function(){
var myId = $(this).attr('id').replace('brandgroupopen-', '');
$('.init-hidden').hide();
$('#brandgroupoptions-' + myId).slideToggle("slow");
});
这是小提琴链接:http: //jsfiddle.net/soniayastays/HHj3N/