2014-02-24 37 views
0

我一次只想展开/折叠一个容器。当我点击第一个容器时,第二个容器应该折叠,当第二个容器展开时,第一个容器应该自动折叠。以下是小提琴。请指导...谢谢展开/收起问题

http://jsfiddle.net/awaises/eK8X5/1138/

jQuery 

$(".header").click(function() { 
    $header = $(this); 
    $content = $header.next();  
    $content.slideToggle(500, function() { 
     $header.text(function() { 
      return $content.is(":visible") ? "Collapse" : "Expand"; 
     }); 
    }); 
}); 
+0

为什么不使用手风琴的文字? http://jqueryui.com/accordion/ – phron

回答

2

您可以将此行添加到您单击处理程序:

$(".header").not(this).text('Expand').next().slideUp(); 

Updated Fiddle

0

你可以找到任何扩展的content元素然后崩溃它像

$('.content').not($content).stop(true).filter(':visible').slideUp(500, function(){ 
    $(this).prev().text('Expand') 
}) 

演示:Fiddle

0

使用此

$(".content").not($content).slideUp(); 

调用的slideToggle功能和ofcourse之前不要忘了更新的标题