我有几个单选按钮组,具体取决于在每个组中选择了哪个单选按钮,该特定答案需要返回 1 个或多个预设在数组中的值。
因此,如果在第 1 组中选择 1,则 A 和 B 值都增加 1,如果选择 B,则 C 和 D 增加,依此类推。最后应返回具有最多分数/增量的字母(提交表格时)
我该怎么办?我认为起点是返回选定的单选按钮,将它们与正确的数组索引匹配,然后检查该数组(字母)中增量最多的值并返回它的值?
$(function(){
var group1 = new Array();
group1[0] = "A, B";
group1[1] = "B, C, D";
group1[2] = "E, B";
group1[3] = "B";
group1[4] = "F";
var group2 = new Array();
group2[0] = "D, A";
group2[1] = "D, C";
group2[2] = "B, F, E";
group2[3] = "A";
group2[4] = "B, D";
$('form').submit(function(){
var checked = $('input:radio:checked').length;
//This is as far as I am
});
});
<form>
<input type="radio" name="group1" value="1" id="q1-1" /> 1
<input type="radio" name="group1" value="2" id="q1-2" /> 2
<input type="radio" name="group1" value="3" id="q1-3" /> 3
<input type="radio" name="group1" value="4" id="q1-4" /> 4
<input type="radio" name="group1" value="5" id="q1-5" /> 5
<br /><br />
<input type="radio" name="group2" value="1" id="q2-1" /> 1
<input type="radio" name="group2" value="2" id="q2-2" /> 2
<input type="radio" name="group2" value="3" id="q2-3" /> 3
<input type="radio" name="group2" value="4" id="q2-4" /> 4
<input type="radio" name="group2" value="5" id="q2-5" /> 5
<input type="submit" value="submit" />
</form>