我想知道如何在HTML中隐藏一行。使用style="empty-cells : hide;"
的CSS方法似乎有效,但如果<h4>
标记包含在空表中,则该行不会被隐藏。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
</head>
<body>
<form name="form_simple" action=" " method="get">
<table border="1px" style="empty-cells : hide;">
<tr><td><h4>Empty cells should not have any borders around them</h4></td></tr>
<tr><td></td></tr>
<tr><td><h4>Empty cells should not have any borders around them.</h4></td></tr>
<tr><td><h4>Empty cells should not have any borders around them.</h4></td></tr>
</table>
</form>
</body>
</html>
style="empty-cells : hide;"
适用于<tr><td></td></tr>
,但适用于<tr><td><h4></h4></td></tr>
答案 0 :(得分:1)
您可以使用javascript执行此操作:
var rows = document.getElementsByTagName('tr');
for (var i=0;i<rows.length;i++) {
var t = rows[i].innerText || rows[i].textContent;
if (t.trim().length==0) rows[i].style.display='none';
}
答案 1 :(得分:1)