2013-06-04 47 views
4

选择一个单选按钮我有带收音机的字段(选择一个问题),我想预选编程页上显示的选项控制组中的单选按钮,这里是对照组:在一个字段通过编程

<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"); 
+0

问题对象的外观如何? –

+0

问题是一个看起来像这个问题的数组对象({'quest':'“,'optiona':”“,'optionsb':”“,'correct':”“}),我不认为这是重要的cos我试图做的是跟踪每个问题的用户选择的答案,当用户再次导航到问题时,他的选择将被预先选中 – kolexinfos

回答

5

工作例如:http://jsfiddle.net/Gajotres/aawNj/

$(document).on('pagebeforeshow', '#index', function(){ 
    $("#optiona").prop("checked", false).checkboxradio("refresh");  
    $("#optionb").prop("checked", true).checkboxradio("refresh"); 
}); 

或另一个工作示例:http://jsfiddle.net/Gajotres/EFzxj/

$(document).on('pagebeforeshow', '#index', function(){ 
    $("#optionb").prop("checked", true); 
    $('#content').trigger('create'); 
}); 
+0

这可以工作,但它不会清除以前选择的选项,因此您有2个选项被选中在对照组中,如何清除对照组中的所有选定选项。 – kolexinfos

+0

更好地看看我的例子,他们都清除前一个。第一个带有“checked”,false,第二个带有触发器('create');当然触发器创建必须在data-role =“content”的DIV上执行。再次,看看我的例子,一切都在那里。 – Gajotres

+0

在选择正确的答案之前,我需要取消选择此组中的任何单选按钮 – kolexinfos

相关问题