【发布时间】:2015-06-12 13:02:43
【问题描述】:
例如我有这个代码:
<table>
<caption>Test</caption>
<tr>
<th>Values</th>
<td>$100</td>
</tr>
<tr>
<th>Initial value</th>
<td class="results"></td>
</tr>
</table>
有没有办法仅使用 HTML/CSS 隐藏等于 $0 的单元格? 假设我有一个名为 fee 的变量而不是 $0,它可以是多种值:$0、$20、$100 等。
例如:
<script>
var fees = ["$0", "$20", "$100"];
document.querySelector('.results').innerHTML = fees[1];
</script>
有没有办法检查它是什么值,如果发现它是 $0,我可以隐藏它吗?
我的 CSS 是:
table{
border-width: 1px;
border-style: solid;
border-collapse: separate;
width: 400px;
}
#test{
empty-cells: show;
margin-bottom: 20px;
}
tr, th, td{
border-width:1px;
border-style: solid;
}
.results {
display: none; // I want this to only display none when fees = $0
}
【问题讨论】:
-
为了计算这样的东西,你需要javascript。 CSS 和 HTML 是标记语言,不能计算这样的内容。
-
不。 HTML 或 CSS 无法读取值。你需要一种脚本语言来做到这一点。
-
没有。但是,如果您要动态填充
td内容,也许您还可以将data-attribute应用到具有该值的td并使用CSS 定位它。到那时你也可以申请一个课程。
标签: javascript html css html-table cell