无法重新选择单选按钮

时间:2013-07-05 12:23:31

标签: javascript jquery json html5 radio-button

我做了一点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"})
    }
  });
}

1 个答案:

答案 0 :(得分:-1)

在单选按钮中使用选中属性。

<input type="radio" selected value="1"/>

请在下面尝试jQuery,

$("radio option[value='B']").attr("selected","selected");