我一直在try 创建一个树(比如目录树),它使用尽可能多的CSS和尽可能少的JS(仅适用于州等),我想知道是否有一些适用于bootstrapjquery-ui bootstrap的好的现有树插件.


For reference or for people confused about this question, I am looking for something like dynatree for bootstrap.

推荐答案

Building on Vitaliy's CSS and Mehmet's jQuery, I changed the a tags to span tags and incorporated some Glyphicons and badging into my take on a Bootstrap tree widget.

Example: my take on a Bootstrap tree widget

For extra credit, I've created a Github iconGitHub project to host the jQuery and LESS code that goes into adding this tree component to Bootstrap. Please see the project documentation at http://jhfrench.github.io/bootstrap-tree/docs/example.html.

Alternately, here is the LESS source to generate that CSS (the JS can be picked up from the jsFiddle):

@import "../../../external/bootstrap/less/bootstrap.less"; /* substitute your path to the bootstrap.less file */
@import "../../../external/bootstrap/less/responsive.less"; /* optional; substitute your path to the responsive.less file */

/* collapsable tree */
.tree {
    .border-radius(@baseBorderRadius);
    .box-shadow(inset 0 1px 1px rgba(0,0,0,.05));
    background-color: lighten(@grayLighter, 5%);
    border: 1px solid @grayLight;
    margin-bottom: 10px;
    max-height: 300px;
    min-height: 20px;
    overflow-y: auto;
    padding: 19px;
    a {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        width: 90%;
    }
    li {
        list-style-type: none;
        margin: 0px 0;
        padding: 4px 0px 0px 2px;
        position: relative;
        &::before, &::after {
            content: '';
            left: -20px;
            position: absolute;
            right: auto;
        }
        &::before {
            border-left: 1px solid @grayLight;
            bottom: 50px;
            height: 100%;
            top: 0;
            width: 1px;
        }
        &::after {
            border-top: 1px solid @grayLight;
            height: 20px;
            top: 13px;
            width: 23px;
        }
        span {
            -moz-border-radius: 5px;
            -webkit-border-radius: 5px;
            border: 1px solid @grayLight;
            border-radius: 5px;
            display: inline-block;
            line-height: 14px;
            padding: 2px 4px;
            text-decoration: none;
        }
        &.parent_li > span {
            cursor: pointer;
            /*Time for some hover effects*/
            &:hover, &:hover+ul li span {
                background: @grayLighter;
                border: 1px solid @gray;
                color: #000;
            }
        }
        /*Remove connectors after last child*/
        &:last-child::before {
            height: 30px;
        }
    }
    /*Remove connectors before root*/
    > ul > li::before, > ul > li::after {
        border: 0;
    }
}

Jquery相关问答推荐

为什么函数没有进入

如何使 Bootstrap 轮播滑块使用移动左/右滑动

将日期时间从 javascript 传递给 c# (Controller)

Bootstrap 的工具提示在悬停时将表格单元格向右移动一点

提交前添加 POST 参数

Jquery Ajax,从 mvc.net 控制器返回成功/错误

jQuery ajax() 使用成功、错误和完成与 .done()、.fail() 和 always()

如何计算具有相同类的元素数量?

清除并刷新 jQuery Chosen 下拉列表

用jquery查找div底部的位置

找到下一个匹配的sibling 姐妹的有效,简洁的方法?

jQuery 序列化不注册复选框

在没有 jQuery 的情况下在 node.js 上合并或合并 JSON

JQuery .hasClass 用于 if 语句中的多个值

带有 jquery 的 jsonp

使用 jQuery DataTables 时禁用第一列的自动排序

如何使用 jQuery 在悬停时显示工具提示消息?

jQuery表格行中的每个循环

5秒后jQuery自动隐藏元素

在jQuery中获取列表元素内容的数组