手风琴一次打开一个选项卡

手风琴一次打开一个选项卡

问题描述:

我有一个手风琴,它工作得很好,但我需要一次只打开一个标签,这意味着当一个标签打开时,另一个标签应该关闭.

I have a accordion which is working absolutely fine but what I need is to open only one tab at a time, means when one tab is opened then another tab should be closed.

目前你可以看到我们可以通过点击标签链接打开所有标签.

Currently you can see that we can open all the tabs by clicking on tab links.

代码在这里

$("#accordion > li > span").click(function() {
  $(this).siblings("div").slideToggle(250);
        $(this).toggleClass("active");

});

这是小提琴

Here is the Fiddle

LIVE DEMO

$("#accordion > li > span").click(function() {
    $(this).closest('li').siblings().find('span').removeClass('active').next('div').slideUp(250);
    $(this).toggleClass("active").next('div').slideToggle(250);
});

或者像:现场演示

$("#accordion > li > span").click(function() {
    $(this).toggleClass("active").next('div').slideToggle(250)
    .closest('li').siblings().find('span').removeClass('active').next('div').slideUp(250);
});