【问题标题】:How to hide panel-body is empty?如何隐藏面板主体为空?
【发布时间】:2016-11-21 22:18:33
【问题描述】:

如果 panel-body 为空,我想隐藏它。

示例如下:BootPly

代码 Javascript:

$(function() {
    $('#container').load(function() {
        if($.trim($(this).contents().find("container").find('panel-body').length) == 0) {
            $(this).hide();
        }
    }); 

代码 HTML:

<div class="container">
    <div class="row clearfix">
        <div class="col-md-9 column">
            <div class="panel panel-primary">
                <div class="panel-heading">Content</div>
                <div class="panel-body fixed-panel">
                    <div class="form-group">

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

【问题讨论】:

  • 您需要确保load 事件触发您的代码运行,并且您的.find() 选择器似乎在类名前面缺少.

标签: javascript twitter-bootstrap panel


【解决方案1】:

这样的事情怎么样? http://www.bootply.com/bKb0isdzKA

$(function() {
    $('.form-group').each(function() {
        if ($(this).is(':empty')) {
            $(this).closest('.container').hide();
        }
    });
});

您遇到了一些问题。一方面,您使用#container 作为选择器,尽管container 是一个。此外,您正在检查 body-panel 是否为空,但它包含一个子 div,因此它始终包含 HTML 内容。

上面的代码将遍历每个.form-group,如果父容器为空,则隐藏父容器。

如果这与您的想法不完全一致,请告诉我,我可以进行调整。

【讨论】:

  • 我建议切换类 hidden 反对使用 show/hide。在我看来,它对于引导程序来说更快且移动方便。
  • 嗨 Santi,不工作,请查看链接:bootply.com/3IZnJQlOqu
猜你喜欢
  • 2012-04-25
  • 1970-01-01
  • 2017-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多