我的程序有问题。这是我的代码片段。
这是 Javascript/Jquery 代码。
<script language='javascript'>
///SELECTING CHECKBOXES////
$(function(){
// add multiple select / deselect functionality
$("#selectall").click(function () {
$('.case').attr('checked', this.checked);
});
// if all checkbox are selected, check the selectall checkbox
// and viceversa
$(".case").click(function(){
if($(".case").length == $(".case:checked").length) {
$("#selectall").attr("checked", "checked");
} else {
$("#selectall").removeAttr("checked");
}
});
});
</script>
这是我将集成该 javascript 的代码。
<h2>Quotation ID</h2>
<?php
$select_orders = mysql_query ("SELECT * FROM tblorder WHERE project_id = '$project_id' GROUP BY quotation_id") OR DIE (mysql_error());
while ($row2=mysql_fetch_array($select_orders)){
$quote_id = $row2['quotation_id'];
?>
<h3 class="expand"><?php echo $quote_id; ?></h3>
<div class="collapse">
<table align='center' border='1' class='display'>
<thead>
<th><input type='checkbox' onclick='checkall()' id='selectall'/></th>
<th>Product Type</th>
<th width='20px'>Product type code</th>
<th width='20px'>Quantity</th>
<th>Width</th>
<th>Height</th>
<th>Total Sub.</th>
</thead>
<tbody>
<?php
$tots_tots = 0;
$tots_subs = 0;
$select_orders2 = mysql_query ("SELECT * FROM tblorder WHERE project_id = '$project_id' AND quotation_id = '$quote_id'") OR DIE (mysql_error());
while ($row3=mysql_fetch_array($select_orders2)){
$idd = $row3['id'];
$project_id2 = $row3['project_id'];
$order_id = $row3['quotation_id'];
$prod_type = $row3['prod_type'];
$prod_type_code = $row3['prod_type_code'];
$qty = $row3['qty'];
$width = $row3['width'];
$height = $row3['height'];
$tot_sub = $row3['total_subs'];
$tots_subs += $tot_sub;
echo "<tr bgcolor='".$colors[$c++ % 2]."' align='center'>";
echo "<td>
<input type='hidden' name='project_name' value='$project_name'>
<input type='checkbox' name='check_ptc[]' value='$prod_type_code' style='display:none;' checked>
<input type='checkbox' class='case' name='checkbox[]' value='".$idd."'></td>";
echo "
<input type='hidden' name='project_id[]' value='$project_id2'>
</td>";
echo "<td>".$prod_type."
<input type='hidden' name='quotation_id[]' value='$order_id'>
<input type='hidden' name='prod_type[]' value='$prod_type'>
</td>";
echo "<td>".$prod_type_code."
<input type='hidden' name='prod_type_code[]' value='$prod_type_code'>
</td>";
echo "<td>".$qty."</td>";
echo "<td>".$width."</td>";
echo "<td>".$height."</td>";
echo "<td>".$tot_sub."</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td></td><td></td><td></td><td></td><td></td>
<td>
<strong><b>Total:</b></strong>";
echo "</td>";
echo "<td>
<font color='#900'><u><b>$tots_subs</b></u></font>
</td>";
echo "</tr>";
?>
</tbody>
</table>
</div>
<?php
}
?>
由于表在循环中。问题是当第一个表出现时。并单击第一个标题复选框,它将检查其他表中的所有复选框。我不想发生。我正在寻找的是,如果有一种方法我还可以迭代复选框的 ID 及其类。或者还有其他方法可以做我想做的事情。
如你看到的。这 3 个表有自己的复选框标题,我想在那里检查所有表。你有什么聪明的主意我该怎么做。
提前致谢..