获取多个相同name的input并给value赋值

//单选题
//多选题
//获取input框的数组
var inputs =$("#select_answer_radio input[name='optext']");
//遍历input,并将数据放入input中
$.each(inputs,function (index,value) {
    $(this).val(oprextArr[index].optext);
})
//获取单选框的数组
var corrects = $("#select_answer_radio input:radio");
//遍历radio,并将数据放入radio中
$.each(corrects,function (index,value) {
    if(oprextArr[index].correct == 'YN01'){
        $(this).val(oprextArr[index].correct);
        $(this).prop('checked', true);
        layform.render('radio');
    }
})
//获取复选框的数组
var corrects = $("#select_answer_checkbox  input:checkbox");
//遍历checkbox,并将数据放入checkbox中
$.each(corrects,function (index,value) {
    if(oprextArr[index].correct == 'YN01'){
        $(this).val(oprextArr[index].correct);
        $(this).prop('checked', true);
        layform.render('checkbox');
    }
})

你可能感兴趣的:(获取多个相同name的input并给value赋值)