项目列表,内容扩展点击,如果项目已经展开,然后崩溃

List of items, content expands on click, if item already expanded then collapse

本文关键字:项目 然后 崩溃 列表 扩展 如果      更新时间:2023-09-26

基本上,我有一个项目列表,其内容在单击时展开。只有一个项目的内容可以一次展开-即,如果我点击一个项目,它的内容将展开,另一个项目的内容将崩溃。

我要找的是,如果一个项目被点击,它的内容已经扩展,我想它崩溃。就像我现在的代码一样,如果内容已经展开,并且点击了项目,那么内容就会重新展开。

非常感谢你的帮助!

JS

$('.image-container').click(function() {
     $('.text-container').hide(200);
     $(this).next('.text-container').show(400);
});   
HTML

<div id="class1" class="image-container">
    <a href="#">An Image</a>
</div>
<div id="class1-container" class="text-container">
    <p>Some Content</p>
</div>
 <div id="class2" class="image-container">
    <a href="#">An Image</a>
 </div>
 <div id="class2-container" class="text-container">
     <p>Some Content</p>
 </div>

参见http://jsfiddle.net/esgk2hve/

$('.image-container').click(function() {
     $('.text-container').not($(this).next()).hide(200);
     $(this).next('.text-container').toggle(400);
});
相关文章: