Dead simple Collapsable List Function for deep and shallow nested UL/LI lists (JQuery)

邮差的信 提交于 2019-12-17 17:00:54

问题


I waded through a TON of terrible js "solutions" for how to simply make collapsible nested list(s).

This is what I eventually came up with.

I'm posting here in the hopes the next guy won't have to deal with all the rufuse out there.

Otherwise feel free to add your own! maybe jquery free method if you can manage it?

  • list must be in "proper" format to work

回答1:


css:

ul>li>ul {
    display: none;
}

js/jquery

$('li').click(function(e){
    e.stopPropagation();
    if(this.getElementsByTagName("ul")[0].style.display =="block")
        $(this).find("ul").slideUp();
    else
        $(this).children(":first").slideDown();
});

jfiddle



来源:https://stackoverflow.com/questions/31508500/dead-simple-collapsable-list-function-for-deep-and-shallow-nested-ul-li-lists-j

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