【问题标题】:Toggle issue with blog posts: How can I close all my opened blog posts when another post title is clicked?切换博客文章问题:单击另一个文章标题时,如何关闭所有打开的博客文章?
【发布时间】:2012-09-12 22:02:22
【问题描述】:

我使用 jQuery 切换了我的博客文章。目前我可以单击帖子标题并同时打开它们,但我希望在单击另一个帖子标题时关闭所有帖子。我需要在我的 jQuery 代码中添加哪一行来执行此操作?我已经被困在这个问题上很长时间了,所以如果有人能帮我解决这个问题,我将非常感激。

这是我的代码:

<script type="text/javascript">
$(document).ready(function() {
$('.toggle-section').hide();
});
</script>

<script type="text/javascript">
$(function() {
$('.entry-title').click(function() {
$(this).closest('.post').find('.toggle-section').slideToggle();     
return false;
});
});
</script>

【问题讨论】:

    标签: jquery wordpress toggle blogs


    【解决方案1】:

    我设计了一个 jsfiddle here!,不确定这是否是您想要的,但我敢打赌它会有所帮助。

       $(document).ready(function() {
           $('.toggle-section').hide();
    
           $('.entry-title').click(function() {
               $('.toggle-section:visible').slideToggle();
               $(this).closest('.post').find('.toggle-section:hidden').slideToggle();
    
           });
    
       });
    

    我更新了代码和小提琴以支持在单击相同标题时隐藏

    【讨论】:

    • 哇,太棒了。有效!谢谢!不过只有一个小问题...当我再次单击打开的条目标题时,它保持打开状态。如何关闭它?
    猜你喜欢
    • 2017-09-26
    • 2015-10-05
    • 1970-01-01
    • 2012-08-26
    • 1970-01-01
    • 1970-01-01
    • 2021-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多