【发布时间】:2014-10-26 06:17:22
【问题描述】:
我有 2 个表格,我想获得这 2 个表格的相加值。 示例:在 q1 我选择 2,在 q2 我选择 4,在我的班级结果中我想显示 6。 该解决方案也应该适用于 30 种表格:)
HTML
<div class="q1">
<form>
<input type="radio" name="q1" value="1"> 1
<input type="radio" name="q1" value="2"> 2
<input type="radio" name="q1" value="3"> 3
<input type="radio" name="q1" value="4"> 4
</form>
</div>
<div class="q2">
<form>
<input type="radio" name="q2" value="1"> 1
<input type="radio" name="q2" value="2"> 2
<input type="radio" name="q2" value="3"> 3
<input type="radio" name="q2" value="4"> 4
</form>
</div>
<div class="result"></div>
jQuery
我得到了值,但我无法添加它们。
$('.q1').on('click',function(){
var r1 = $('input[name=q1]:checked').val();
$('.result').html(r1);
});
$('.q2').on('click',function(){
var r2 = $('input[name=q2]:checked').val();
$('.result').html(r2);
});
【问题讨论】:
标签: jquery radio-button