jQuery check radio option not checking
I can't get the radio options to check on my page. They won't c开发者_如何学Check Yes or No.
for (var i = 0; i < r.length; i++) {
jQuery('#condition-'+i+'-price').val(r[i].price);
jQuery('#condition-'+i+'-bid').val(r[i].bid);
console.log('[value='+r[i].on_amazon+']');
console.log(jQuery('#condition-'+r[i].condition_id+'-on_amazon').filter('[value='+r[i].on_amazon+']'));
jQuery('#condition-'+r[i].condition_id+'-on_amazon').filter('[value='+r[i].on_amazon+']').attr('checked', true);
}
r[i].on_amazon is always 1 or 0 and condition_id is correct because price/bid successfully update...
<tr>
<td><label for="on_amazon-1-yes">Yes</label></td>
<td class="yes"><input type="radio" id="condition-1-on_amazon" value="1"></td>
<td> </td>
<td class="no"><input type="radio" id="condition-1-on_amazon" value="0"></td>
<td><label for="on_amazon-1-no">No</label></td>
</tr>
Set $(radiobtn).attr('checked','checked')
instead of true
, assuming you're using XHTML.
Try doing:
jQuery('#condition-'+r[i].condition_id+'-on_amazon').filter('[value='+r[i].on_amazon+']')[0].checked=true;
精彩评论