我想知道如果我的jquery是正確的添加td並獲得總計的小計和總數。jQuery與php上表tr tr總和的列總計
我jQuery是,
$(document).ready(function(){
var sum = 0;
var td = $('input[name=sumof]').val();
jQuery.each(td,function(number){
sum += parseInt($(this).val());
$('#total_f').val(sum);
});
})
,這是我的HTML
<div class="quotation_computation" style="margin-top:50px;">
<table cellpadding="5" cellspacing="0" width="100%">
<tr>
<th>#</th>
<th>Definition</th>
<th>Amount</th>
<th>Total</th>
<th>BTW</th>
</tr>
<?
$get_details = mysql_query("SELECT * FROM jon_com_quo_computation WHERE com_code = '".$_GET['ccom']."' ") or die (mysql_error());
$found_record = mysql_num_rows($get_details);
if ($found_record != 0) {
while($set_det = mysql_fetch_array($get_details)) {
$total = $set_det['quo_quantity'] * $set_det['quo_amt'];
?>
<tr>
<td class="add_text">
<?=$set_det['quo_quantity'];?> x
</td>
<td class="add_text" width="250"><?=$set_det['quo_definition'];?></td>
<td class="sum_text">
<?=$set_det['quo_amt'];?>
<input type="hidden" name="sumof" value="<?=$set_det['quo_amt'];?>" />
</td>
<td class="add_text" id="total"><?=$total;?></td>
<td class="add_text"><?=$set_det['quo_btw'];?></td>
</tr>
<?
}
} else {
?>
<tr>
<td class="add_text">#</td>
<td class="add_text">Definition</td>
<td class="add_text">Amount</td>
<td class="add_text" id="total">Total</td>
<td class="add_text">BTW</td>
</tr>
<?
}
?>
</table>
</div>
<div class="sub_total_computation" style="width:200px; position:relative; left:325px;">
<?
$get_total_computation = SET_SQL("SELECT quo_btw FROM jon_com_quo_computation WHERE com_code = '".$_GET['ccom']."' ");
?>
<table cellpadding="5" cellspacing="0" width="100%">
<tr>
<td><strong>Sub Total</strong></td>
<td>
<span id="total_f"></span>
<input type="hidden" name="total_f" value="" />
</td>
</tr>
<tr>
<td><?=$get_total_computation['quo_btw'];?></td>
<td><?=$btw;?></td>
</tr>
<tr>
<td><strong>Total</strong></td>
<td><?=$btw;?></td>
</tr>
</table>
</div>
,如果你看到了hidden name=sumof
我去把那裏的答案也在td class=sum_text
但答案沒有出現。 我們是否需要在.keyup
函數上使用,這樣jquery纔會出現? 或者我只需要使用PHP
,這樣它就可以工作?
謝謝先生。
謝謝先生!這麼多:) – Butternut
很高興幫助! :) – jtheman