【发布时间】:2013-06-04 15:19:26
【问题描述】:
我有一个带有单选的字段集(问题的选项),我想在页面显示上以编程方式在选项控制组中预选一个单选按钮,这里是控制组:
<fieldset data-role="controlgroup" id="options">
<input type="radio" name="radio-choice-1" id="optiona" value="a"
checked="checked" />
<label for="optiona" id="labela">Ondo</label>
<input type="radio" name="radio-choice-1" id="optionb" value="b" />
<label for="optionb">Lagos</label>
<input type="radio" name="radio-choice-1" id="optionc" value="c" />
<label for="optionc">Abuja</label>
<input type="radio" name="radio-choice-1" id="optiond" value="d" />
<label for="optiond">Kogi</label>
<input type="radio" name="radio-choice-1" id="optione" value="e" />
<label for="optione">Niger</label>
</fieldset>
我尝试了以下方法:
var sel = questions[indexNo].correct;
$("#option" + sel).prop("checked", true)
$("#option"+ sel).is(":checked");
【问题讨论】:
-
问题对象是什么样子的?
-
Questions 是一个数组对象,看起来像这个 question({'quest':"",'optionsa':"",'optionsb':"",'correct':""}),我不认为这很重要,因为我要做的是在用户再次导航到问题时跟踪用户每个问题选择的答案,他的选择应该被预先选择
标签: jquery jquery-mobile