繁体   English   中英

无图像的Bootstrap目录树-字体真棒图标未更改

[英]images-less Bootstrap Directory Tree - font-awesome icons not changing

我正在使用bootstrap创建无映像的目录树,到目前为止,我已经设法做到了这一点。 但字体真棒图标未显示。 参考: https : //github.com/jhfrench/bootstrap-tree

HTML

<div class="tree">
    <ul>
        <li><span><i class="fa fa-folder-open-o"></i> Parent</span> <a href="">Goes somewhere</a>
            <ul>
                <li><span><i class="fa fa-minus-square-o"></i> Child</span> <a href="">Goes somewhere</a>
                <ul>
                <li><span><i class="fa fa-leaf"></i> Grand Child</span> <a href="">Goes somewhere</a>
                </li>
                </ul>
                </li>

                <li><span><i class="fa fa-minus-square-o"></i> Child</span> <a href="">Goes somewhere</a>
                    <ul>
                        <li><span><i class="fa fa-leaf"></i> Grand Child</span> <a href="">Goes somewhere</a>
                        </li>

                        <li><span><i class="fa fa-minus-square-o"></i> Grand Child</span> <a href="">Goes somewhere</a>
                            <ul>
                                <li><span><i class="fa fa-minus-square-o"></i> Great Grand Child</span> <a href="">Goes somewhere</a>
                                <ul>
                                <li><span><i class="fa fa-leaf"></i> Great great Grand Child</span> <a href="">Goes somewhere</a>
                                </li>
                                <li><span><i class="fa fa-leaf"></i> Great great Grand Child</span> <a href="">Goes somewhere</a>
                                </li>
                                </ul>
                                </li>

                                <li><span><i class="fa fa-leaf"></i> Great Grand Child</span> <a href="">Goes somewhere</a>
                                </li>

                                <li><span><i class="fa fa-leaf"></i> Great Grand Child</span> <a href="">Goes somewhere</a>
                                </li>
                            </ul>
                        </li>

                        <li><span><i class="fa fa-leaf"></i> Grand Child</span> <a href="">Goes somewhere</a>
                        </li>
                    </ul>
                </li>
            </ul>
        </li>

        <li><span><i class="fa fa-folder-open-o"></i> Parent2</span> <a href="">Goes somewhere</a>
            <ul>
                <li><span><i class="fa fa-leaf"></i> Child</span> <a href="">Goes somewhere</a>
                </li>
            </ul>
        </li>
    </ul>
</div>

CSS

@import url("http://netdna.bootstrapcdn.com/bootswatch/3.0.3/cerulean/bootstrap.min.css");
@import url("http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css");
@import url("http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css");

.tree {
    min-height:20px;
    padding:0px;
    margin-bottom:20px;
}

.tree li {
    list-style-type:none;
    margin:0;
    padding:13px 0px 0px 0px;
    position:relative
}
.tree li::before, .tree li::after {
    content:'';
    left:-20px;
    position:absolute;
    right:auto
}
.tree li::before {
    border-left:1px solid #999;
    bottom:50px;
    height:100%;
    top:0;
    width:1px
}
.tree li::after {
    border-top:1px solid #999;
    height:20px;
    top:25px;
    width:25px
}
.tree li span {

    display:inline-block;
    padding:3px 8px;
    text-decoration:none
}
.tree li.parent_li>span {
    cursor:pointer
}
.tree>ul>li::before, .tree>ul>li::after {
    border:0
}
.tree li:last-child::before {
    height:25px
}
.tree li.parent_li>span:hover, .tree li.parent_li>span:hover+ul li span {
    background:#eee;
    border:1px solid #94a0b4;
    color:#000
}

JAVASCRIPT

$(function () {
    $('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');
    $('.tree li.parent_li > span').on('click', function (e) {
        var children = $(this).parent('li.parent_li').find(' > ul > li');
        if (children.is(":visible")) {
            children.hide('fast');
            $(this).attr('title', 'Expand this branch').find(' > i').addClass('fa fa-plus-square-o').removeClass('fa fa-minus-square-o');
        } else {
            children.show('fast');
            $(this).attr('title', 'Collapse this branch').find(' > i').addClass('fa fa-minus-square-o').removeClass('fa fa-plus-square-o');
        }
        e.stopPropagation();
    });
});

http://jsfiddle.net/GpdgF/990/

在上面的示例中,字体真棒图标未呈现。

谢谢你的时间。

问题是:

addClass('fa fa-plus-square-o').removeClass('fa fa-minus-square-o');

addClassremoveClass假定参数是一个类列表,以空格分隔,它将首先删除类fafa-plus-square-o ,然后添加类fafa-plus-square-o 与两次调用addClassremoveClass相同,如下所示:

$('.select')
    .addClass('fa')
    .addClass('fa-plus-square-o')
    .removeClass('fa')
    .removeClass('fa-minus-square-o');

这就是addClass和removeClass函数的功能:即使可能有10个其他类,您也只能从一个元素中删除一个类名。

在您的代码中,您根本不需要添加/删除fa类,因此您只需删除/添加fa-*类,它就可以工作。

另外,您也可以颠倒顺序,这样就可以了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM