我需要做的是在<h2>
单击时切换每个搜索区域。
我还需要它来切换<h2> <span>
元素上的类 icon-minus 和 icon plus。(这没有显示在我的小提琴上,因为它需要安装字体。)
在加载时,它应该只显示第一个搜索区域,其余部分隐藏(显示:无)。
它还必须能够切换当前搜索区域和图标。
我有一个蹩脚的尝试jsFiddle
你可以这样做。您只需要添加一个.not()以便当前 div 不会与其他 div 一起隐藏
$('.s-container h2').on('click', function () {
var $el = $(this);
var div = $el.next('.s-area');
$('.s-area').not(div).hide(); // hide all but the current one that is toggling
div.slideToggle('fast',function(){
// add correct class accordingly to the h2 elemeents
$('.s-container h2').attr('class',function(){
return $(this).next('.s-area').is(':visible') ? 'icon-minus' : 'icon-plus';
});
});
});