我一直在网站上下以及与此相关的各种问题,我找不到解决方案。
每当我的span“specvalue”不包含数据时,我都会尝试隐藏我的父div“row”
<div class="container-fluid" id="itmSpecsTbl">
<div class="row" id="row"><div class="col-xs-6" align="left"><b>Accuracy</b> </div><div class="col-xs-6" align="right"><span id="specvalue"><%=getAttribute('item','127559','custitem1','')%></span> </div></div>
<div class="row" id="row"><div class="col-xs-6" align="left"><b>Drive Type</b> </div><div class="col-xs-6" align="right"><span id="specvalue"><%=getAttribute('item','127559','custitem2','')%></span> </div></div>
<div class="row" id="row"><div class="col-xs-6" align="left"><b>Free Speed</b> </div><div class="col-xs-6" align="right"><span id="specvalue"><%=getAttribute('item','127559','custitem4','')%></span> RPM</div></div>
<div class="row" id="row"><div class="col-xs-6" align="left"><b>Increments</b> </div><div class="col-xs-6" align="right"><span id="specvalue"><%=getAttribute('item','127559','custitem5','')%></span> </div></div>
<div class="row" id="row"><div class="col-xs-6" align="left"><b>Length</b> </div><div class="col-xs-6" align="right"><span id="specvalue"><%=getAttribute('item','127559','custitem6','')%></span> In</div></div>
<div class="row" id="row"><div class="col-xs-6" align="left"><b>Length</b> </div><div class="col-xs-6" align="right"><span id="specvalue"><%=getAttribute('item','127559','custitem7','')%></span> mm</div></div>
<div class="row" id="row"><div class="col-xs-6" align="left"><b>Max Air Consumption</b> </div><div class="col-xs-6" align="right"><span id="specvalue"><%=getAttribute('item','127559','custitem8','')%></span> </div></div>
<div class="row" id="row"><div class="col-xs-6" align="left"><b>Air Inlet (NPT)</b> </div><div class="col-xs-6" align="right"><span id="specvalue"><%=getAttribute('item','127559','custitem37','')%></span> </div></div>
<div class="row" id="row"><div class="col-xs-6" align="left"><b>Min Torque</b> </div><div class="col-xs-6" align="right"><span id="specvalue"><%=getAttribute('item','127559','custitem9','')%></span> ft lb</div></div>
<div class="row" id="row"><div class="col-xs-6" align="left"><b>Max Torque</b> </div><div class="col-xs-6" align="right"><span id="specvalue"><%=getAttribute('item','127559','custitem10','')%></span> ft lb</div></div>
<div class="row" id="row"><div class="col-xs-6" align="left"><b>Min Torque</b> </div><div class="col-xs-6" align="right"><span id="specvalue"><%=getAttribute('item','127559','custitem11','')%></span> in lb</div></div>
<div class="row" id="row"><div class="col-xs-6" align="left"><b>Max Torque</b> </div><div class="col-xs-6" align="right"><span id="specvalue"><%=getAttribute('item','127559','custitem12','')%></span> in lb</div></div>
<div class="row" id="row"><div class="col-xs-6" align="left"><b>Min Torque</b> </div><div class="col-xs-6" align="right"><span id="specvalue"><%=getAttribute('item','127559','custitem13','')%></span> in oz</div></div>
<div class="row" id="row"><div class="col-xs-6" align="left"><b>Max Torque</b> </div><div class="col-xs-6" align="right"><span id="specvalue"><%=getAttribute('item','127559','custitem14','')%></span> in oz</div></div>
<div class="row" id="row"><div class="col-xs-6" align="left"><b>Min Torque</b> </div><div class="col-xs-6" align="right"><span id="specvalue"><%=getAttribute('item','127559','custitem15','')%></span> kgf cm</div></div>
<div class="row" id="row"><div class="col-xs-6" align="left"><b>Max Torque</b> </div><div class="col-xs-6" align="right"><span id="specvalue"><%=getAttribute('item','127559','custitem16','')%></span> kgf cm</div></div>
<div class="row" id="row"><div class="col-xs-6" align="left"><b>Capacity</b> </div><div class="col-xs-6" align="right"><span id="specvalue"><%=getAttribute('item','127559','custitemfi0073','')%></span> lbs</div></div>
<div class="row" id="row"><div class="col-xs-6" align="left"><b>Min Reach</b> </div><div class="col-xs-6" align="right"><span id="specvalue"><%=getAttribute('item','127559','custitemfi0103','')%></span> in</div></div>
<div class="row" id="row"><div class="col-xs-6" align="left"><b>Max Reach</b> </div><div class="col-xs-6" align="right"><span id="specvalue"><%=getAttribute('item','127559','custitemfi0104','')%></span> in</div></div>
</div>
当没有数据时,“getAttribute”用于提取项目的数据。它是空白的 - 没有空格,没有。
我尝试过使用:empty,:blank
#specvalue:empty #row, #specvalue:blank #row { display: none; }
这让我无处可去,与jquery相同
$("#specvalue:empty").parent().hide();
到目前为止,没有任何工作,我甚至尝试将脚本放在<head>
标签内,甚至在调用技术文档后放下。
你认为我需要更具体的CSS吗?我看到它适用于其他例子,但不是这个。
答案 0 :(得分:2)
我已删除了重复的id="row"
,并将id="specvalue"
替换为class="specvalue"
。然后使用一些简单的jquery,我隐藏了所有具有空specvalue的行。
注意:始终保持在minde id 始终必须在完整的html页面中是唯一的!
$('.specvalue').each(function(i, v) {
if ($(this).html() === '') {
$(this).closest('.row').hide();
}
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-fluid" id="itmSpecsTbl">
<div class="row">
<div class="col-xs-6" align="left"><b>Accuracy</b>
</div>
<div class="col-xs-6" align="right"><span class="specvalue">A</span>
</div>
</div>
<div class="row">
<div class="col-xs-6" align="left"><b>Drive Type</b>
</div>
<div class="col-xs-6" align="right"><span class="specvalue"></span>
</div>
</div>
<div class="row">
<div class="col-xs-6" align="left"><b>Free Speed</b>
</div>
<div class="col-xs-6" align="right"><span class="specvalue">B</span> RPM</div>
</div>
</div>
&#13;
答案 1 :(得分:0)
对于每种类型的元素,您的所有ID都是相同的 - 不要这样做!一旦你修复了它,你将需要使用该类作为选择器,然后你可以在jQuery中做这样的事情:
if ($('.row').is(':empty')){
$(this).parent()hide().
}
然后用类行检查每个元素,如果它没有内容,则获取父元素并将其隐藏。
答案 2 :(得分:0)
您可以在CSS中执行此操作,但问题是您对每个id
使用相同的span
属性。 id
对于整个文档(see this)必须是唯一的。使用class
代替:
<span class="specvalue"><%=getAttribute('item','127559','custitem1','')%></span>
CSS:
.specvalue:empty {
display: none;
}
答案 3 :(得分:0)
所以就像你的评论中所说:ID是唯一的,所以使用类。
这是您的解决方案:JSFiddle
HTML:
<div class="container-fluid" id="itmSpecsTbl">
<div class="row">
<div class="col-xs-6" align="left">
<b>Accuracy</b>
</div>
<div class="col-xs-6" align="right">
<span class="specvalue"></span>
</div>
</div>
<div class="row">
<div class="col-xs-6" align="left">
<b>Drive Type</b>
</div>
<div class="col-xs-6" align="right">
<span class="specvalue"></span>
</div>
</div>
<div class="row">
<div class="col-xs-6" align="left">
<b>Free Speed</b>
</div>
<div class="col-xs-6" align="right">
<span class="specvalue">RPM</span>
</div>
</div>
<div class="row">
<div class="col-xs-6" align="left">
<b>Increments</b>
</div>
<div class="col-xs-6" align="right">
<span class="specvalue"></span>
</div>
</div>
</div>
JS:
var rows = $('#itmSpecsTbl .row');
$.each(rows, function(i, e){
if($(e).find('.specvalue').text() === ''){
$(e).hide();
}
});