是否可以使用CSS隐藏表行,我有一个需要这个概念的项目.这是我的代码:
style.css中:
#hide-row { display:none; }
Run Code Online (Sandbox Code Playgroud)
file.php
<table>
<tr>
<th>Name</th>
<th>Address</th>
</tr>
<div id="hide-row">
<?php foreach( $cops as $row ) { ?>
<tr>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->address; ?></td>
</tr>
<?php } ?>
</div>
</table>
Run Code Online (Sandbox Code Playgroud)
但是,它没有用,记录仍然出现.有人帮忙解决这个案子吗?任何帮助将不胜感激.先谢谢你!
jan*_*mon 10
使用类而不是id:
.hide-row { display:none; }
Run Code Online (Sandbox Code Playgroud)
在你的html/php文件中:
<table>
<tr>
<th>Name</th>
<th>Address</th>
</tr>
<?php foreach( $cops as $row ) { ?>
<tr class="hide-row">
<td><?php echo $row->name; ?></td>
<td><?php echo $row->address; ?></td>
</tr>
<?php } ?>
</table>
Run Code Online (Sandbox Code Playgroud)
如果必须对行进行分组,则可以使用tbody标记而不是div标记.
.hide-row tr { display:none; }
Run Code Online (Sandbox Code Playgroud)
在你的html/php文件中:
<table>
<tr>
<th>Name</th>
<th>Address</th>
</tr>
<tbody class="hide-row">
<?php foreach( $cops as $row ) { ?>
<tr>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->address; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)