如何在php / html中隐藏整个空列
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了如何在php / html中隐藏整个空列,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2367字,纯文字阅读大概需要4分钟。
内容图文
![如何在php / html中隐藏整个空列](/upload/InfoBanner/zyjiaocheng/680/63bcc09cb08a4f1e8793d5ac9877f6bc.jpg)
只是想隐藏我表中的所有空列.
该表的代码如下:
<table width="100%" border="1" cellspacing="2" cellpadding="2" id="weatherTable">
<tr>
<th align="center" valign="bottom" bgcolor="#CCCCCC"><strong>DISPLAYED REPORTS AVERAGES:</strong></th>
<td align="center" valign=bottom><font size="4"><b><strong>--</strong></b></font></td>
<td align="center" valign=bottom><font size="4"><b><?php echo $row["air_temp"]; ?></b></font></td>
<td align="center" valign=bottom><font size="4"><?php echo $row["sea_temp"]; ?></font></td>
</tr>
<tr>
<th align="center" valign="bottom" bgcolor="#CCCCCC"><strong>Station (ID)</strong></td>
<th align="center" valign="bottom" bgcolor="#CCCCCC"><strong>Time<br>(UTC)</strong></td>
<th align="center" valign="bottom" bgcolor="#CCCCCC"><strong>Air Temp<br>(°C)</strong></td>
<th align="center" valign="bottom" bgcolor="#CCCCCC"><strong>Sea Temp<br>(°C)</strong></td>
</tr>
<tr>
if (($sth-> rowCount())>0) {
foreach (($sth->fetchAll(PDO::FETCH_ASSOC)) as $col) {
?>
<tr>
<td align="right" valign=top><?php echo $col["name"] . " (" . $col["dim_stationID"] . ")"; ?></td>
<td align="center" valign=top><?php $d = $col["date_time"]; $t = explode(" ",$d); $s = explode (":",$t[1]); echo "".$s[0]."".$s[1].""; ?> </td>
<td align="center" valign=top><?php echo $col["air_temp"]; ?></td>
<td align="center" valign=top><?php echo $col["sea_temp"]; ?></td>
</tr>
数据填充在这4列ID每行的每个报表中,并且我已经在表格顶部为每一列设置了平均值,所以现在最后一列“ Sea Temp”为空,如何隐藏整个字段柱?
PS:我正在编码
$('td:empty').each(function(i){
$(this).hide().parents('weatherTable').find('th:nth-child('+(i+1)+')').hide();
});
但是该代码将隐藏每个空字段(不需要),例如“ Air Temp”列下有三行用于不同的报告,并且该列中有一行包含数据,另外两行为空.从逻辑上讲,由于整个列都不为空,因此不应隐藏该列.
解决方法:
正如在Hiding a table column if the containing cells are empty with jQuery(由maclema回答)中所回答的那样,您可以使用如下所示的内容:
var numCols = $("th", table).length;
for ( var i=1; i<=numCols; i++ ) {
var empty = true;
//grab all the <td>'s of the column at i
$("td:nth-child(" + i + ")", table).each(function(index) {
//check if the td is not empty
if ( $(this).text() != "" ) {
empty = false;
return false; //break out of each() early
}
});
if ( empty ) {
$("td:nth-child(" + i + ")", table).hide(); //hide <td>'s
$("th:nth-child(" + i + ")", table).hide(); //hide header <th>
}
}
内容总结
以上是互联网集市为您收集整理的如何在php / html中隐藏整个空列全部内容,希望文章能够帮你解决如何在php / html中隐藏整个空列所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。