JQuery 隐藏 UL 并且只扩展一次特定的类集(有点像手风琴) [英] JQuery hide ULs and only expand once particular class set (bit like an accordion)
问题描述
对的人,
在与 JQuery Accordion 尝试做我想做的事情之后,我认为隐藏所有辅助 UL 并且只在我的 CMS 自动在 lis 上设置的一个类中扩展它们将是最简单的事情.我想要手风琴类型的功能,但是当特定的 ul 处于活动状态时,它必须展开/向下滑动.我已经意识到典型的 JQuery 手风琴不适合,因为我不会在 CMS 菜单输出中显示切换 li.
After battling with a JQuery Accordion trying to do what I want I think hiding all secondary UL's and only expanding them once a class my CMS sets automatically on lis would be the easiest thing. I want to have accordion type functionality, but it must expand/slide down when that particular ul is active. I have realized that a typical JQuery accordion will not suit, as I will not have toggle li's present in the CMS menu output.
此处的菜单代码:
<ul id="amenu">
<li><a href="anotherpage.html">Home</a></li><li><span class="currentbranch0">
<a href="anotherpage2.html">Content</a></span>
<ul class="multilevel-linkul-0" title="">
<li><a href="subpage.html">Content 2</a></li>
<li><span class="currentbranch1"><a href="subpage.html">Content 3</a></span></li>
</ul>
</li>
//How to target this command to multilevel-linkul-0 class?
$(function(){
$('ul li ul').slideDown();
});
(小提琴:http://jsfiddle.net/Dmhcq/5/)
-- 更新了 Fiddle 以准确显示我的意思,我只希望带有 currentbranch1 的辅助 UL 向下滑动
-- Updated Fiddle to show exactly what I mean, I only want the secondary UL with currentbranch1 to slideDown
使用此代码,基本上任何具有跨度类currentbranch1"的东西都应该slideDown,其余的应该保持隐藏.我一直在查看示例 JQuery 代码,甚至不知道从哪里开始,我不是 JS 程序员 :) .所以不幸的是,上面是我最好的尝试.如果有人有任何建议,将不胜感激.:)
With this code, basically anything with span class "currentbranch1" should slideDown and the rest should remain hidden. I have been looking at sample JQuery code and am completely at a loss even where to start, I'm not a JS programmer :) . So unfortunately above is my best stab at it. If anyone has any advice it would be much appreciated. :)
干杯
尼克
推荐答案
很简单.你需要反过来做.找到类为currentbranch1"的元素并向上遍历到multilevel-linkul-0"父元素并让它向下滑动.
It's simple. You need to do it the other way around. Find the element that has the class "currentbranch1" and traverse up to the "multilevel-linkul-0" parent and tell that to slide down.
代码
//How to target this command to multilevel-linkul-0 class?
$(function(){
$('.currentbranch1').parents('ul.multilevel-linkul-0').slideDown();
});
这是一个小提琴示例.
这篇关于JQuery 隐藏 UL 并且只扩展一次特定的类集(有点像手风琴)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!