【发布时间】:2016-10-03 22:03:03
【问题描述】:
我正在尝试将表格最后一列的内容加粗,但不确定如何选择这些键值并使用 jquery 应用一个非常新的粗体。
<?php
$items = array(
array("City" => "Dalas","Age" => "47", "Name" => "Janet Fuller", "Address" => "445 Upland Pl.", "Status" => "Trial"),
array("City" => "Lyon", "Age" => "38", "Name" => "Andrew Heiniger", "Address" => "347 College Av.", "Status" => "Active"),
array("City" => "Dallas", "Age" => "43", "Name" => "Susanne Smith", "Address" => "2 Upland Pl.", "Status" => "Active"),
array("City" => "Paris", "Age" => "25", "Name" => "Sylvia Steel", "Address" => "269 College Av.", "Status" => "Suspended"),
array("City" => "San Francisco", "Age" => "7", "Name" => "James Peterson", "Address" => "231 Upland Pl.", "Status" => "Active"),
array("City" => "Oslo", "Age" => "42", "Name" => "Robert Ott", "Address" => "503 Seventh Av.", "Status" => "Trial")
);
?>
<?php if (count($items) > 0): ?>
<table>
<thead>
<tr>
<th><?php echo implode('</th><th>', array_keys(current($items))); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($items as $row): array_map('htmlentities', $row); ?>
<tr>
<td><?php echo implode('</td><td>', $row); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
【问题讨论】:
-
网页中的内容样式化(如果这就是您所说的“粗体”)通常不是通过逻辑来完成的,无论是客户端还是服务器端,而是通过样式表,因此 css 文件。
-
我不认为我可以选择键“状态”并将值设置为粗体,在 css 中。
-
有像
:last-child这样的选择器,您可以将其应用于表格单元格... -
将 $("td:last-child").css("font-weight:", "bold");工作吗?
-
您朝着正确的方向前进,但如前所述:您不想按照客户端逻辑执行此操作,因此在 javascript 中。你为什么想这么做?使用 css 文件。更简单、更高效。
标签: php jquery arrays html-table