我做了一点web quiz。
问题是当点击后退按钮时,我想重新选择用户的最后选择,但它似乎不起作用,我不明白为什么。
这是我的go_back
功能:
function go_back(){
$("#back").bind("click",function(){
qNum--;
if(AnsW.length === 0){
calcAnswers--;
}
tempAns = AnsW[qNum];
//user's last answer, which is false. I need this to make the radio button point to that answer.
showQuestion(qNum);
$("#contain").find("input[value="+tempAns+"]").prop('checked', true);
AnsW.splice(-1,1);
//delete the false answer from the array. I need this to make sure that the answer is deleted and there won't be an overload of wrong answers
if(qNum === 0){
$("#back").css({"visibility":"hidden"})
}
});
}
答案 0 :(得分:-1)
在单选按钮中使用选中属性。
<input type="radio" selected value="1"/>
请在下面尝试jQuery,
$("radio option[value='B']").attr("selected","selected");