Сообщение от рони
|
PHP Useless,
важно только классы
у table => class="qrup"
у строк предметов tr => class="study" data-k="1"
куда выводить td => class="interim"
общий результат td => class="result"
остальное куда хотите и что хотите
массив fb только заполните по количеству таблиц.
всё
|
поменял на это новый(второй) блок не работает
<table width="100" class="qru" >
<thead>
<tr>
<th bgcolor="#E0E0E0">Fənnlər</th>
<th bgcolor="#E0E0E0">D</th>
<th bgcolor="#E0E0E0">D-A</th>
<th bgcolor="#E0E0E0">Y</th>
<th bgcolor="#E0E0E0">FB</th>
</tr>
</thead>
<tbody>
<tr class="stud" data-k="1">
<td>sdfds</td>
<td><input name="" size="3" maxlength="2"></td>
<td><input name=""size="3" maxlength="2"></td>
<td><input name="" size="3" maxlength="2"></td>
<td class="interi" ></td>
</tr>
<tr class="stud" data-k="2">
<td>Riyaziyyat</td>
<td><input name="" size="3" maxlength="2"></td>
<td><input name="" size="3" maxlength="2"></td>
<td><input name="" size="3" maxlength="2"></td>
<td class="interi"></td>
</tr>
<tr class="stud" data-k="2">
<td>Fizika</td>
<td><input name="" size="3" maxlength="2"></td>
<td><input name="" size="3" maxlength="2"></td>
<td><input name="" size="3" maxlength="2"></td>
<td class="interi"></td>
</tr>
<tr class="stud" data-k="1">
<td>Kimya</td>
<td><input name="" size="3" maxlength="2"></td>
<td><input name="" size="3" maxlength="2"></td>
<td><input name="" size="3" maxlength="2"></td>
<td class="interi"></td>
</tr>
<tr class="stud" data-k="1">
<td>Xarici dil</td>
<td><input name="" size="3" maxlength="2"></td>
<td><input name="" size="3" maxlength="2"></td>
<td><input name="" size="3" maxlength="2"></td>
<td class="interi"></td>
</tr>
<tr>
<td colspan="3" ></td>
<td>Sizin Balınız:</td>
<td class="resul"></td>
</tr>
</tbody>
</table>
<script>
var fb = [ function(a, b, c) {
return 4 * a + 4*b - c
}],
total = function(a) {
return a.reduce(function(a, b) {
return a + b
}, 0)
};
[].forEach.call(document.querySelectorAll(".qru"), function(table, i) {
var sum = [],
resul = table.querySelector(".resul");
[].forEach.call(table.querySelectorAll(".stud"), function(tr, n) {
var temp = [],
interi = tr.querySelector(".interi"), k = +tr.dataset.k||1;
sum[n] = 0;
[].forEach.call(tr.querySelectorAll("input"), function(input, j) {
temp[j] = 0;
input.addEventListener("input", function() {
var val = +input.value || 0;
input.value = temp[j] = val;
sum[n] = fb[i].apply(null, temp) * k;
interim.innerHTML = sum[n];
result.innerHTML = total(sum)
})
})
})
});
</script>