<td>&nbsp;</td>
<td><span id="hiddenappraisalitemid<%=i%>" style="display:none;" ><s:property value='id'/></span></td>
<td align="left"><span id="hiddenradio<%=i%>_1" ><input id="answer<%=i%>_1" align="left" type="radio" name="appraisalAnswer<%=i %>" /></span><span id="option<%=i%>_1"><s:property value='option1'/></span></td>
<td>&nbsp;&nbsp;</td>
<td align="left"><span id="hiddenradio<%=i%>_2"><input id="answer<%=i%>_2" type="radio" name="appraisalAnswer<%=i %>" /></span><span id="option<%=i%>_2"><s:property value='option2'/></span></td>
<td>&nbsp;&nbsp;</td>
<td align="left"><span id="hiddenradio<%=i%>_3"><input id="answer<%=i%>_3" type="radio" name="appraisalAnswer<%=i %>" /></span><span id="option<%=i%>_3"><s:property value='option3'/></span></td>
<td>&nbsp;&nbsp;</td>
<td align="left"><span id="hiddenradio<%=i%>_4"><input id="answer<%=i%>_4" type="radio" name="appraisalAnswer<%=i %>" /></span><span id="option<%=i%>_4" ><s:property value='option4'/></span></td>
<td>&nbsp;&nbsp;</td>
<td align="left"><span id="hiddenradio<%=i%>_5"><input id="answer<%=i%>_5" type="radio" name="appraisalAnswer<%=i %>" /></span><span id="option<%=i%>_5" ><s:property value='option5'/></span></td>
<td>&nbsp;</td>

有上边这样一组单选按钮

<input id="answer<%=i%>_2" type="radio" name="appraisalAnswer<%=i %>" />

怎么设置单选按钮的属性,使得一旦选中某一个单选按钮,就不可编辑单选按钮呢?


这是查看学生试卷的代码段。

if(document.getElementById("answer"+(i+2)+"_"+answers_array[i]).checked){   
alert(answers_array[i]);
if(answers_array[i]==1){
document.getElementById("answer"+(i+2)+"_"+2).disabled="true";
document.getElementById("answer"+(i+2)+"_"+3).disabled="true";
document.getElementById("answer"+(i+2)+"_"+4).disabled="true";
document.getElementById("answer"+(i+2)+"_"+5).disabled="true";
}else if(answers_array[i]==2){
document.getElementById("answer"+(i+2)+"_"+1).disabled="true";
document.getElementById("answer"+(i+2)+"_"+3).disabled="true";
document.getElementById("answer"+(i+2)+"_"+4).disabled="true";
document.getElementById("answer"+(i+2)+"_"+5).disabled="true";
}else if(answers_array[i]==3){
document.getElementById("answer"+(i+2)+"_"+1).disabled="true";
document.getElementById("answer"+(i+2)+"_"+2).disabled="true";
document.getElementById("answer"+(i+2)+"_"+4).disabled="true";
document.getElementById("answer"+(i+2)+"_"+5).disabled="true";
}else if(answers_array[i]==4){
document.getElementById("answer"+(i+2)+"_"+1).disabled="true";
document.getElementById("answer"+(i+2)+"_"+2).disabled="true";
document.getElementById("answer"+(i+2)+"_"+3).disabled="true";
document.getElementById("answer"+(i+2)+"_"+5).disabled="true";
}else if(answers_array[i]==5){
document.getElementById("answer"+(i+2)+"_"+2).disabled="true";
document.getElementById("answer"+(i+2)+"_"+3).disabled="true";
document.getElementById("answer"+(i+2)+"_"+4).disabled="true";
document.getElementById("answer"+(i+2)+"_"+1).disabled="true";
}
}

我用了最笨的一种方法解决了这个 问题,还有简单点的吗?


1个回答

可以修改的智能点,不需要一个一个写,建议分两步:

1、用for循环将所有的answer禁用;

2、根据answers_array[i]的值,选择特定元素来启用。