[英]How to hide panel-body is empty?
I want to hide panel-body if it is empty. 我想隐藏面板主体,如果它是空的。
Here's the example: BootPly 这是示例: BootPly
Code Javascript: 代码Javascript:
$(function() {
$('#container').load(function() {
if($.trim($(this).contents().find("container").find('panel-body').length) == 0) {
$(this).hide();
}
});
Code HTML: 代码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>
How about something like this? 这样的事情怎么样? http://www.bootply.com/bKb0isdzKA
http://www.bootply.com/bKb0isdzKA
$(function() {
$('.form-group').each(function() {
if ($(this).is(':empty')) {
$(this).closest('.container').hide();
}
});
});
You had a few issues. 您遇到了一些问题。 For one, you were using
#container
as your selector, despite container
being a class . 例如,尽管
container
是一个类 ,但您还是使用#container
作为选择器。 Additionally, you were checking to see if body-panel
was empty, but it contained a child div, so it would always have HTML content. 另外,您正在检查
body-panel
为空,但其中包含子div,因此它将始终具有HTML内容。
The code above will loop through each .form-group
and hide the parent container if it's empty. 上面的代码将遍历每个
.form-group
并隐藏父容器(如果为空)。
If this isn't exactly what you had in mind, let me know and I can make adjustments. 如果这不是您真正想的,请告诉我,我可以进行调整。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.