【发布时间】:2011-08-19 09:11:13
【问题描述】:
大家好,我有一个带有几个复选框的表格,所有这些复选框在它们旁边的隐藏输入中都有一个数值。我想在我的小表格底部的输入文本中显示这些总和。我来到了下面的脚本,但事实证明我的 JS 和 JQuery 知识(方式?)很少。有什么线索可以知道最好的方法是什么?
<td>
<input checked="checked" type="checkbox" class="processPaymentProducts" name="processPaymentProducts[]" value="<?=$transaction['student_transaction_id']?>" />
<input type="hidden" id="prodPrice[<?=$transaction['student_transaction_id']?>]" name="prodPrice[<?=$transaction['student_transaction_id']?>]" value="<?=($transaction['student_transaction_amount_min']*100)?>" />
</td>
<script>
$(document).ready(function() {
$(".processPaymentProducts").click(function(){
var amount;
$amount = 0;
jQuery.each($(".processPaymentProducts:checked").val(), function() {
$amount += $(this).next('input').val();
console.log($(this).next('input').val());
});
if($amount>100) { $amount = $amount/100; } else { $amount = 0; }
$('#processPaymentAmount').val($amount);
});
});
</script>
【问题讨论】:
-
我已经更新了演示和解释...希望对您有所帮助
标签: php javascript jquery jquery-selectors