How can I use nested accordion menus without multiple instances?

旧巷老猫 提交于 2019-12-08 02:29:34

问题


Here's my base:

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?


回答1:


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();​


来源:https://stackoverflow.com/questions/12920458/how-can-i-use-nested-accordion-menus-without-multiple-instances

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!