분명히 이것은 작동해야하지만 작동하지 않습니다.
HTML :
<form id="myForm">
<label>
20
<input id="fb3" type="radio" name="fb1" value="20" />
</label>
<label>
35
<input id="fb4" type="radio" name="fb1" value="35" />
</label>
<label>
10
<input id="fb1" type="radio" name="fb" value="10" />
</label>
<label>
15
<input id="fb2" type="radio" name="fb" value="15" />
</label>
<br/>
Total: <span id="totalScore">0</span>€
</form>
그리고 js :
var sum = 0;
$("#myForm").find("input[type='radio']:checked").each(function (i, e){sum+=$(e).val();});
$("#totalScore").val(sum);
나는 여기에서 본 모든 것을 stackoverflow에서 시도했지만 코드에 무엇이 잘못되었는지 알 수 없습니다. 실제로이 솔루션은 누군가가 이미 게시 한 예제 중 하나입니다.
이 시도
function calcscore(){
var score = 0;
$("input[type='radio']:checked").each(function(){
score+=parseInt($(this).val());
});
$("#totalScore").text(score)
}
$().ready(function(){
$("input[type='radio']").change(function(){
calcscore()
});
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다