이 특성에 대한 질문은 여러 차례 묻지 만 여러 가지를 시도한 후 몇 시간 후에 나는 여전히 현명하지 않습니다. 바라건대 누군가가 나를 계몽 할 수 있기를 바랍니다.jQuery로 여러 입력의 합계를 계산하십시오.
여러 입력 값을 추가하고 합계 값을 별도의 필드에 출력하려고합니다. 다음 스 니펫은 작업을 수행하지만 각기 다른 ID로 동적으로 생성되므로 각 시즌을 반복해야합니다. 그것이 너무에 대한 내 머리을하고있어 내가 여기에 대한 도움을 주셔서 감사합니다 것
var sum = 0;
$('.appearances').each(function(){
sum = sum + Number($(this).val());
});
$('#season-0 .appearances').html(sum);
:
$('#season-0 .appearances').val(
Number($('#season-4 .appearances').val()) +
Number($('#season-36 .appearances').val())
);
$('#season-0 .goals').val(
Number($('#season-4 .goals').val()) +
Number($('#season-36 .goals').val())
);
내가 몇 가지 기능만을 시도했습니다 예를 들어, 작동하는 것 같군
아 내가 볼<div id="season-0">
<table>
<tr>
<td>
<input type="text" data-index="appearances" class="appearances" value="" />
</td>
<td>
<input type="text" data-index="goals" class="goals" value="" />
</td>
</tr>
</table>
</div>
<div id="season-4">
<table>
<tr>
<td>
<input type="text" data-index="appearances" class="appearances" value="25" />
</td>
<td>
<input type="text" data-index="goals" class="goals" value="4" />
</td>
</tr>
</table>
</div>
<div id="season-36">
<table>
<tr>
<td>
<input type="text" data-index="appearances" class="appearances" value="19" />
</td>
<td>
<input type="text" data-index="goals" class="goals" value="8" />
</td>
</tr>
</table>
</div>
대리인 HTML은 무엇입니까 : 여기
는 바이올린입니까? –시간을내어 HTML을 포함하도록 게시물을 편집했습니다. – roofdog