用于深层和浅层嵌套UL / LI列表的死简单可折叠列表函数(JQuery) [英] Dead simple Collapsable List Function for deep and shallow nested UL/LI lists (JQuery)

查看:171
本文介绍了用于深层和浅层嵌套UL / LI列表的死简单可折叠列表函数(JQuery)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我介绍了如何简单地制作可折叠嵌套列表的可怕的 js解决方案。

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

这是我最终想出来的。

我发布在这里希望下一个人不必处理那里的所有rufuse。

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

否则随意添加自己的!如果你可以管理它可能是jquery免费方法?

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

  • list must be in "proper" format to work

推荐答案

css:

ul>li>ul {
    display: none;
}

js / jquery

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

这篇关于用于深层和浅层嵌套UL / LI列表的死简单可折叠列表函数(JQuery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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