【发布时间】:2018-05-18 23:38:26
【问题描述】:
在这个表格中,我想用 jQuery 添加一个新的表格单元格。
<table cellspacing="0" cellpadding="2" class="table">
<tr class="dataTableHeadingRow">
<td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS; ?></td>
<td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS_MODEL; ?></td>
</tr>
<?php
for ($i = 0, $n = sizeof($order->products); $i < $n; $i ++) {
echo '<tr class="dataTableRow">';
echo ' <td class="dataTableContent txta-r">' . $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . '</td>';
echo ' <td class="dataTableContent txta-r">' . $order->products[$i]['model'] . '</td>';
/* here should the new table cell be */
echo '</tr>';
}
?>
</table>
<?php include changes.php; ?>
在不改变原始代码的情况下,此 CMS 需要文件 changes.php 来更改代码。 新的表格标题不是问题。
$new_th = '<td class="dataTableHeadingContent">' . TABLE_NEW_CELL . '</td>';
?>
<script>
$(document).ready(function() {
$("td:contains('<?php echo TABLE_HEADING_PRODUCTS_MODEL; ?>')" ).after('<?php echo $new_th; ?>');
});
</script>
但是如何在这个 for 循环中添加一个新的表格单元格呢?
【问题讨论】: