gpt4 book ai didi

jQuery 可折叠 UL

转载 作者:搜寻专家 更新时间:2023-10-31 22:31:09 26 4
gpt4 key购买 nike

我正在使用 jQuery 创建一个导航系统。我想要实现的是在页面加载时显示父元素并隐藏子元素。我做得非常简单。

然而,当我在其他父元素之间切换时,我希望能够隐藏之前的子元素,以便我只能打开一个 <ul>一次。

//user nav
$('.child').hide();
$('.parent').click(function() {
$(this).find('ul').slideToggle();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<div class="rightBottom">
<h1 class="boxheadings">Other functions</h1>
<p class="boxp">Click this button to view your current published site in a new window. This will not show your most recent changes until you click the ‘Publish Changes’ button on the right, alternatively click view local to see unpublished changes.</p>
<ul id="usernav">
<li class="parent">Manage
<ul class="child">
<li>child11</li>
<li>child12</li>
</ul>
</li>
<li class="parent">Subscriptions
<ul class="child">
<li>E-Briefings</li>
<li>E-Briefings Subscriptions</li>
<li>Knowledge Briefings</li>
</ul>
</li>
<li class="parent">Media Store
<ul class="child">
<li>Image Store</li>
<li>Document Store</li>
<li>Media Store</li>
</ul>
</li>
</ul>
</div>

最佳答案

完成。这很简单。在显示当前 ul 之前,我隐藏了所有内容。

见:

//hide all children initially
$('.child').hide();

//adding a click handlers to every all parents
$('.parent').click(function() {

//slide up the children which are open already
$('.child').slideUp();

//find the child of clicked parent and toggle its visibility
$(this).find('ul').slideToggle();
});

关于jQuery 可折叠 UL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18824213/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com