编辑
现在我有这个html:
<table id="consumo">
<thead>
<tr>
<th>Semana</th>
<th colspan="7">Consumo de alimento diario</th>
<th rowspan="2">Total Semana</th>
<th rowspan="2">Acumulado</th>
<th rowspan="2">Consumo Diario</th>
<th rowspan="2">Consumo por pollo semana</th>
<th rowspan="2">Consumo Acumulado</th>
</tr>
<tr>
<td></td>
<td>Lunes</td>
<td>Martes</td>
<td>Miércoles</td>
<td>Jueves</td>
<td>Viernes</td>
<td>Sábado</td>
<td>Domingo</td>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td><input class="con_sem_1" name="con_lun[]" type="text"
onkeypress="numeric(event)" size="6" value=""></td>
<td><input class="con_sem_1" name="con_mar[]" type="text"
onkeypress="numeric(event)" size="6" value=""></td>
<td><input class="con_sem_1" name="con_mie[]" type="text"
onkeypress="numeric(event)" size="6" value=""></td>
<td><input class="con_sem_1" name="con_jue[]" type="text"
onkeypress="numeric(event)" size="6" value=""></td>
<td><input class="con_sem_1" name="con_vie[]" type="text"
onkeypress="numeric(event)" size="6" value=""></td>
<td><input class="con_sem_1" name="con_sab[]" type="text"
onkeypress="numeric(event)" size="6"></td>
<td><input class="con_sem_1" name="con_dom[]" type="text"
onkeypress="numeric(event)" size="6" value=""></td>
<td><input id="tot_sem_1" disabled="disabled" size="7"></td>
<td><input id="acum_sem_1" disabled="disabled" size="7"></td>
<td><input id="con_diario_sem_1" disabled="disabled" size="7"></td>
<td><input id="con_x_pollo_sem_1" disabled="disabled" size="7"></td>
<td><input id="con_acum_sem_1" disabled="disabled" size="7"></td>
</tr>
</tbody>
</table>
这个javascript代码:
function calcular() {
var total = 0;
$(".con_sem_1").each(function(){
if (!isNaN(this.value)) {
total += parseInt(this.value);
}
});
$("#tot_sem_1").val(total);
}
$(document).ready(function() {
$("#consumo").on("keyup", ".con_sem_1", calcular());
});
它仍然无法正常工作。