Fall: Ich habe eine Formulareingabe erstellt, in der alle Schüler angezeigt werden, die pro Klasse teilnehmen und die Werte einzeln eingeben. Ich erstelle erfolgreich onkeyup, um (N.Akhir) zu berechnen, um Wunschwerte zu erhalten. Aber das funktioniert nur in der ersten Reihe, es funktionierte nicht in der nächsten Reihe. Wie funktioniert onkeyup in der nächsten Zeile?Wie funktioniert onkeyup in der nächsten Zeile?
I codeigniter und Javascript bin mit dieser meine Codes
Bitte siehe unten machen:
function hitung2() {
var a = $("#tt1").val();
var b = $("#tt2").val();
var c = $("#tt3").val();
ntt = (parseInt(a) + parseInt(b) + parseInt(c)) /3;
ntt = ntt.toFixed(2);
$("#ntt").val(ntt);
var d = $("#ntt").val();
var e = $("#np").val();
f = (parseInt(e)*3 + parseInt(d)*7) /10
$("#na").val(f);
}
<table class="table table-hover">
<tr>
<th>No</th> \t \t \t \t \t \t
<th>NAMA</th> \t \t \t
<th>TOTAL HADIR</th>
<th>TT 1</th>
<th>TT 2</th>
<th>TT 3</th>
<th>N.RATA"</th>
<th>N.PARTISIPASI</th>
<th>N.AKHIR</th>
</tr>
<?php
if(isset($ambil_data)>0){$i=1; foreach($ambil_data as $row) {
\t \t ?>
\t <tr>
\t \t <td><?php echo $i; ?></td>
\t \t <td><?php echo $row->nama; ?></td>
\t \t <td><input type="text" class="form-control" id="jml_hadir" maxlength="1" name="jml_hadir" placeholder="Hadir" /><?php echo form_error('jml_hadir'); ?></td>
\t \t <td><input type="text" class="form-control" id="tt1" placeholder="TT1" maxlength="5" name="tt1" onkeyup="hitung2()" /><?php echo form_error('tt1'); ?></td>
\t \t <td><input type="text" class="form-control" id="tt2" placeholder="TT1" maxlength="5" name="tt2" onkeyup="hitung2()" /><?php echo form_error('tt2'); ?></td>
\t \t <td><input type="text" class="form-control" id="tt3" placeholder="TT1" maxlength="5" name="tt3" onkeyup="hitung2()" /><?php echo form_error('tt3'); ?></td>
\t \t <td><input type="text" class="form-control" id="ntt" name="ntt" readonly /></td>
\t \t <td><input type="text" class="form-control" id="np" placeholder="N.Partisipasi" name="np" onkeyup="hitung2()"/><?php echo form_error('np'); ?></td>
\t \t <td><input type="text" class="form-control" id="na" name="na" readonly /></td>
\t </tr>
<?php $i++;}}?>
</form>
</table>
Das ist, weil Sie eindeutige ID-Werte oder die Verwendung Klassen haben müssen Ihre Reihen zu isolieren. Dann müssen Sie auf diese isolierten Zeilen verweisen mit '$ (this)' – Rasclatt