在一个DIV打开时关闭所有其他DIV-使用单独的关闭按钮



我有一堆可以打开和关闭的div。它们通过点击DIV"case toggle"打开,并通过一个名为"case close"的单独跨度关闭

点击后显示的DIV具有类"case popup">

问题是多个DIV可以同时打开,但我希望一次只打开一个DIV,其他所有DIV都关闭
我不确定需要在这里添加什么额外的代码才能实现这一点

我已经搜索了又搜索,但在使用单独的关闭按钮时,我没有发现任何问题

这是代码:

$(document).ready(
function(){
$('.case-toggle').click(
function(){
$(this).next('.case-popup').show();  
}
);
$('.case-close').click(
function(){
$(this).closest('.case-popup').hide();  
}
);
}       
);

非常感谢您的帮助!

添加此行

$('.case-popup').hide();

$('.case-toggle').click()功能

$(document).ready(
function() {
$('.case-toggle').click(
function() {
$('.case-popup').hide();
$(this).next('.case-popup').show();
}
);
$('.case-close').click(
function() {
$(this).closest('.case-popup').hide();
}
);    
}
);

像这样使用

$('.case-toggle').on("click", function() {
$('.case-popup').hide();
$(this).next('.case-popup').show();
});

最新更新