【发布时间】:2017-10-08 04:03:50
【问题描述】:
我目前有一个多列表,其中一列是一列充满复选框的列。每当我选中一个复选框时,我都希望在表格的右侧出现一个额外的单元格。目前,当我选中一个复选框时,它会显示整个列,但我希望它只显示相应行中的单元格。
我该怎么做?
我的 PHP/HTML 代码:
<table id="merchTable" cellspacing="5" class="sortable">
<thead>
<tr class="ui-widget-header">
<th class="sorttable_nosort"></th>
<th class="sorttable_nosort">Loc</th>
<th class="merchRow">Report Code</th>
<th class="merchRow">SKU</th>
<th class="merchRow">Special ID</th>
<th class="merchRow">Description</th>
<th class="merchRow">Quantity</th>
<th class="sorttable_nosort">Unit</th>
<th style="display: none;" class="num">Quantity #</th>
</tr>
</thead>
<tbody>
<?php foreach ($dbh->query($query) as $row) {?>
<tr>
<td><input type="checkbox" class="check" name="check"></td>
<td class="loc"></td>
<td class="rp-code" align="center"></td>
<td class="sku"></td>
<td class="special-id" align="center"></td>
<td class="description"></td>
<td class="quantity" align="center"></td>
<td class="unit"></td>
<td style="display: none;" class="quantity_num"></td>
</tr>
<?php } ?>
</tbody>
</table>
我的 JavaScript 代码:
$(function () {
$(".check").change(function(){
$("#merchTable th.num").toggle(this.checked);
$("#merchTable td.quantity_num").toggle(this.checked);
});
});
我已更改我的代码以使其与 JSFiddle 一起使用,因此您可以看到一些关于我目前拥有的和正在发生的事情的示例:
【问题讨论】:
标签: javascript php jquery checkbox html-table