如何在没有多个实例的情况下使用嵌套的手风琴菜单? [英] How can I use nested accordion menus without multiple instances?

查看:21
本文介绍了如何在没有多个实例的情况下使用嵌套的手风琴菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的基地:

http://jsfiddle.net/UnV4Z/

而且我希望它是三个级别而不是两个级别.我已经在这里工作了:

And I want it to be three levels instead of just two. I've got it working here:

http://jsfiddle.net/RnwYQ/13/

但这意味着每个类别必须有一个实例.有没有更干净的方法来做到这一点?

But it means that I've got to have one instance per category. Is there a cleaner way of doing this?

推荐答案

尝试给手风琴一个类并稍微修改代码以使其基于单击的元素隐藏兄弟.

Try giving the accordion a class and slightly modifying the code to make it hide siblings based on clicked element.

http://jsfiddle.net/RnwYQ/19/

$(".accordion > li > div").click(function() {

    if (!$(this).next().is(':visible')) {
        $(this).parent().siblings().children("ul").slideUp(300);
    }
    $(this).next().slideToggle(300);
}).parent().filter(":first-child").children("div").click();​

这篇关于如何在没有多个实例的情况下使用嵌套的手风琴菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆