我在我的页面上汇总所有内容,如下所示:http: //jsfiddle.net/7wWR6/
<script>
$(document).ready(function() {
$('.newreservation').click(function() {
//get the numbers
var rent = parseFloat($('.rentalcharges').find('#rent').val());
var cleaning = parseFloat($('.rentalcharges').find('#cleaning').val());
var booking = parseFloat($('.rentalcharges').find('#booking').val());
var taxes = parseFloat($('.rentalcharges').find('#taxes').val());
var total = 0;
total = total + (rent+cleaning+booking+taxes);
//set the total
$('.rentalcharges').find('#total').val(total);
console.log('total: ' + total);
});
$('input[type=checkbox]').click(function(){
//get the numbers
var rent = parseFloat($('.rentalcharges').find('#rent').val());
var cleaning = parseFloat($('.rentalcharges').find('#cleaning').val());
var booking = parseFloat($('.rentalcharges').find('#booking').val());
var taxes = parseFloat($('.rentalcharges').find('#taxes').val());
var total = 0;
total = total + (rent+cleaning+booking+taxes);
var checked;
if($('input[type=checkbox]').is(':checked')){
checked = parseFloat($('input[type=checkbox]').val());
total = total + checked;
}else{
total = total - checked;
}
//set the total
$('.rentalcharges').find('#total').val(total);
});
});
</script>
除了复选框之外,这一切都有效。他们什么都不做,只记录总共 0。我该如何解决这个问题?如果需要,我会尝试制作一个 jsfiddle。我只是在字段中使用了很多 mySQL,显然不能简单地复制/粘贴。
编辑:我做了一个准系统小提琴,我认为代表我的情况:http: //jsfiddle.net/7wWR6/